summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-11-13 23:45:45 -0800
committerEric Wieser <wieser.eric@gmail.com>2017-11-13 23:45:45 -0800
commitac6b1a902b99e340cf7eeeeb7392c91e38db9dd8 (patch)
tree589c9f85e52a75a16ed949c14bfa39777e651fc4 /numpy/core
parentbd80585cdae1d43fabb30ae0e184c2e40deb11e6 (diff)
downloadnumpy-ac6b1a902b99e340cf7eeeeb7392c91e38db9dd8.tar.gz
ENH: don't show boolean dtype, as it is implied
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/arrayprint.py4
-rw-r--r--numpy/core/code_generators/ufunc_docstrings.py56
-rw-r--r--numpy/core/defchararray.py4
-rw-r--r--numpy/core/fromnumeric.py10
-rw-r--r--numpy/core/numeric.py4
-rw-r--r--numpy/core/tests/test_arrayprint.py10
6 files changed, 45 insertions, 43 deletions
diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py
index 8435574bf..55682f393 100644
--- a/numpy/core/arrayprint.py
+++ b/numpy/core/arrayprint.py
@@ -1129,7 +1129,7 @@ def _void_scalar_repr(x):
return StructureFormat.from_data(array(x), **_format_options)(x)
-_typelessdata = [int_, float_, complex_]
+_typelessdata = [int_, float_, complex_, bool_]
if issubclass(intc, int):
_typelessdata.append(intc)
if issubclass(longlong, int):
@@ -1162,6 +1162,8 @@ def dtype_is_implied(dtype):
array([1, 2, 3], dtype=np.int8)
"""
dtype = np.dtype(dtype)
+ if _format_options['legacy'] and dtype.type == bool_:
+ return False
return dtype.type in _typelessdata
diff --git a/numpy/core/code_generators/ufunc_docstrings.py b/numpy/core/code_generators/ufunc_docstrings.py
index 6aae57234..5626f50d8 100644
--- a/numpy/core/code_generators/ufunc_docstrings.py
+++ b/numpy/core/code_generators/ufunc_docstrings.py
@@ -573,7 +573,7 @@ add_newdoc('numpy.core.umath', 'bitwise_and',
>>> np.bitwise_and(np.array([2,5,255]), np.array([3,14,16]))
array([ 2, 4, 16])
>>> np.bitwise_and([True, True], [False, True])
- array([False, True], dtype=bool)
+ array([False, True])
""")
@@ -630,7 +630,7 @@ add_newdoc('numpy.core.umath', 'bitwise_or',
... np.array([4, 4, 4, 2147483647L], dtype=np.int32))
array([ 6, 5, 255, 2147483647])
>>> np.bitwise_or([True, True], [False, True])
- array([ True, True], dtype=bool)
+ array([ True, True])
""")
@@ -680,7 +680,7 @@ add_newdoc('numpy.core.umath', 'bitwise_xor',
>>> np.bitwise_xor([31,3], [5,6])
array([26, 5])
>>> np.bitwise_xor([True, True], [False, True])
- array([ True, False], dtype=bool)
+ array([ True, False])
""")
@@ -1057,13 +1057,13 @@ add_newdoc('numpy.core.umath', 'equal',
Examples
--------
>>> np.equal([0, 1, 3], np.arange(3))
- array([ True, True, False], dtype=bool)
+ array([ True, True, False])
What is compared are values, not types. So an int (1) and an array of
length one can evaluate as True:
>>> np.equal(1, np.ones(1))
- array([ True], dtype=bool)
+ array([ True])
""")
@@ -1389,14 +1389,14 @@ add_newdoc('numpy.core.umath', 'greater',
Examples
--------
>>> np.greater([4,2],[2,2])
- array([ True, False], dtype=bool)
+ array([ True, False])
If the inputs are ndarrays, then np.greater is equivalent to '>'.
>>> a = np.array([4,2])
>>> b = np.array([2,2])
>>> a > b
- array([ True, False], dtype=bool)
+ array([ True, False])
""")
@@ -1424,7 +1424,7 @@ add_newdoc('numpy.core.umath', 'greater_equal',
Examples
--------
>>> np.greater_equal([4, 2, 1], [2, 2, 2])
- array([ True, True, False], dtype=bool)
+ array([ True, True, False])
""")
@@ -1541,7 +1541,7 @@ add_newdoc('numpy.core.umath', 'invert',
Booleans are accepted as well:
>>> np.invert(array([True, False]))
- array([False, True], dtype=bool)
+ array([False, True])
""")
@@ -1599,7 +1599,7 @@ add_newdoc('numpy.core.umath', 'isfinite',
>>> np.isfinite(np.NINF)
False
>>> np.isfinite([np.log(-1.),1.,np.log(0)])
- array([False, True, False], dtype=bool)
+ array([False, True, False])
>>> x = np.array([-np.inf, 0., np.inf])
>>> y = np.array([2, 2, 2])
@@ -1661,7 +1661,7 @@ add_newdoc('numpy.core.umath', 'isinf',
>>> np.isinf(np.NINF)
True
>>> np.isinf([np.inf, -np.inf, 1.0, np.nan])
- array([ True, True, False, False], dtype=bool)
+ array([ True, True, False, False])
>>> x = np.array([-np.inf, 0., np.inf])
>>> y = np.array([2, 2, 2])
@@ -1709,7 +1709,7 @@ add_newdoc('numpy.core.umath', 'isnan',
>>> np.isnan(np.inf)
False
>>> np.isnan([np.log(-1.),1.,np.log(0)])
- array([ True, False, False], dtype=bool)
+ array([ True, False, False])
""")
@@ -1745,7 +1745,7 @@ add_newdoc('numpy.core.umath', 'isnat',
>>> np.isnat(np.datetime64("2016-01-01"))
False
>>> np.isnat(np.array(["NaT", "2016-01-01"], dtype="datetime64[ns]"))
- array([ True, False], dtype=bool)
+ array([ True, False])
""")
@@ -1814,7 +1814,7 @@ add_newdoc('numpy.core.umath', 'less',
Examples
--------
>>> np.less([1, 2], [2, 2])
- array([ True, False], dtype=bool)
+ array([ True, False])
""")
@@ -1842,7 +1842,7 @@ add_newdoc('numpy.core.umath', 'less_equal',
Examples
--------
>>> np.less_equal([4, 2, 1], [2, 2, 2])
- array([False, True, True], dtype=bool)
+ array([False, True, True])
""")
@@ -2155,11 +2155,11 @@ add_newdoc('numpy.core.umath', 'logical_and',
>>> np.logical_and(True, False)
False
>>> np.logical_and([True, False], [False, False])
- array([False, False], dtype=bool)
+ array([False, False])
>>> x = np.arange(5)
>>> np.logical_and(x>1, x<4)
- array([False, False, True, True, False], dtype=bool)
+ array([False, False, True, True, False])
""")
@@ -2188,11 +2188,11 @@ add_newdoc('numpy.core.umath', 'logical_not',
>>> np.logical_not(3)
False
>>> np.logical_not([True, False, 0, 1])
- array([False, True, True, False], dtype=bool)
+ array([False, True, True, False])
>>> x = np.arange(5)
>>> np.logical_not(x<3)
- array([False, False, False, True, True], dtype=bool)
+ array([False, False, False, True, True])
""")
@@ -2223,11 +2223,11 @@ add_newdoc('numpy.core.umath', 'logical_or',
>>> np.logical_or(True, False)
True
>>> np.logical_or([True, False], [False, False])
- array([ True, False], dtype=bool)
+ array([ True, False])
>>> x = np.arange(5)
>>> np.logical_or(x < 1, x > 3)
- array([ True, False, False, False, True], dtype=bool)
+ array([ True, False, False, False, True])
""")
@@ -2258,17 +2258,17 @@ add_newdoc('numpy.core.umath', 'logical_xor',
>>> np.logical_xor(True, False)
True
>>> np.logical_xor([True, True, False, False], [True, False, True, False])
- array([False, True, True, False], dtype=bool)
+ array([False, True, True, False])
>>> x = np.arange(5)
>>> np.logical_xor(x < 1, x > 3)
- array([ True, False, False, False, True], dtype=bool)
+ array([ True, False, False, False, True])
Simple example showing support of broadcasting
>>> np.logical_xor(0, np.eye(2))
array([[ True, False],
- [False, True]], dtype=bool)
+ [False, True]])
""")
@@ -2647,10 +2647,10 @@ add_newdoc('numpy.core.umath', 'not_equal',
Examples
--------
>>> np.not_equal([1.,2.], [1., 3.])
- array([False, True], dtype=bool)
+ array([False, True])
>>> np.not_equal([1, 2], [[1, 3],[1, 4]])
array([[False, True],
- [False, True]], dtype=bool)
+ [False, True]])
""")
@@ -3102,7 +3102,7 @@ add_newdoc('numpy.core.umath', 'signbit',
>>> np.signbit(-1.2)
True
>>> np.signbit(np.array([1, -2.3, 2.1]))
- array([False, True, False], dtype=bool)
+ array([False, True, False])
""")
@@ -3166,7 +3166,7 @@ add_newdoc('numpy.core.umath', 'nextafter',
>>> np.nextafter(1, 2) == eps + 1
True
>>> np.nextafter([1, 2], [2, 1]) == [eps + 1, 2 - eps]
- array([ True, True], dtype=bool)
+ array([ True, True])
""")
diff --git a/numpy/core/defchararray.py b/numpy/core/defchararray.py
index e5f685369..6d0a0add5 100644
--- a/numpy/core/defchararray.py
+++ b/numpy/core/defchararray.py
@@ -575,9 +575,9 @@ def endswith(a, suffix, start=0, end=None):
array(['foo', 'bar'],
dtype='|S3')
>>> np.char.endswith(s, 'ar')
- array([False, True], dtype=bool)
+ array([False, True])
>>> np.char.endswith(s, 'a', start=1, end=2)
- array([False, True], dtype=bool)
+ array([False, True])
"""
return _vec_string(
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py
index ebeea6319..568d39781 100644
--- a/numpy/core/fromnumeric.py
+++ b/numpy/core/fromnumeric.py
@@ -1567,7 +1567,7 @@ def nonzero(a):
>>> a > 3
array([[False, False, False],
[ True, True, True],
- [ True, True, True]], dtype=bool)
+ [ True, True, True]])
>>> np.nonzero(a > 3)
(array([1, 1, 1, 2, 2, 2]), array([0, 1, 2, 0, 1, 2]))
@@ -1962,7 +1962,7 @@ def any(a, axis=None, out=None, keepdims=np._NoValue):
True
>>> np.any([[True, False], [False, False]], axis=0)
- array([ True, False], dtype=bool)
+ array([ True, False])
>>> np.any([-1, 0, 5])
True
@@ -1973,7 +1973,7 @@ def any(a, axis=None, out=None, keepdims=np._NoValue):
>>> o=np.array([False])
>>> z=np.any([-1, 4, 5], out=o)
>>> z, o
- (array([ True], dtype=bool), array([ True], dtype=bool))
+ (array([ True]), array([ True]))
>>> # Check now that z is a reference to o
>>> z is o
True
@@ -2047,7 +2047,7 @@ def all(a, axis=None, out=None, keepdims=np._NoValue):
False
>>> np.all([[True,False],[True,True]], axis=0)
- array([ True, False], dtype=bool)
+ array([ True, False])
>>> np.all([-1, 4, 5])
True
@@ -2058,7 +2058,7 @@ def all(a, axis=None, out=None, keepdims=np._NoValue):
>>> o=np.array([False])
>>> z=np.all([-1, 4, 5], out=o)
>>> id(z), id(o), z # doctest: +SKIP
- (28293632, 28293632, array([ True], dtype=bool))
+ (28293632, 28293632, array([ True]))
"""
arr = asanyarray(a)
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 25f4d6c35..ac64b0537 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -1193,7 +1193,7 @@ def tensordot(a, b, axes=2):
[ True, True],
[ True, True],
[ True, True],
- [ True, True]], dtype=bool)
+ [ True, True]])
An extended example taking advantage of the overloading of + and \\*:
@@ -1901,7 +1901,7 @@ def fromfunction(function, shape, **kwargs):
>>> np.fromfunction(lambda i, j: i == j, (3, 3), dtype=int)
array([[ True, False, False],
[False, True, False],
- [False, False, True]], dtype=bool)
+ [False, False, True]])
>>> np.fromfunction(lambda i, j: i + j, (3, 3), dtype=int)
array([[0, 1, 2],
diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py
index 62b5cf580..cf5c14435 100644
--- a/numpy/core/tests/test_arrayprint.py
+++ b/numpy/core/tests/test_arrayprint.py
@@ -317,15 +317,15 @@ class TestPrintOptions(object):
def test_bool_spacing(self):
assert_equal(repr(np.array([True, True])),
- 'array([ True, True], dtype=bool)')
+ 'array([ True, True])')
assert_equal(repr(np.array([True, False])),
- 'array([ True, False], dtype=bool)')
+ 'array([ True, False])')
assert_equal(repr(np.array([True])),
- 'array([ True], dtype=bool)')
+ 'array([ True])')
assert_equal(repr(np.array(True)),
- 'array(True, dtype=bool)')
+ 'array(True)')
assert_equal(repr(np.array(False)),
- 'array(False, dtype=bool)')
+ 'array(False)')
def test_sign_spacing(self):
a = np.arange(4.)