8000 BUG: scalar argument to ma.atleast_* return arrays · charris/numpy@b1e5430 · GitHub
[go: up one dir, main page]

Skip to content

Commit b1e5430

Browse files
jjhelmuscharris
authored andcommitted
BUG: scalar argument to ma.atleast_* return arrays
The np.ma.atleast_1d, np.ma.atleast_2d, np.ma.atleast_3d and np.ma.diagflat function return arrays when given a scalar in the same manner as their non-ma counterparts. Previously these function would return None. Additionally, the np.ma vstack, row_stack, hstack, column_stack, dstack, and hsplit functions now raise an expection when given a scalar argument. closes numpy#3367
1 parent b3c772c commit b1e5430

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

numpy/ma/extras.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ def __call__(self, *args, **params):
270270
_d = func(tuple([np.asarray(a) for a in x]), **params)
271271
_m = func(tuple([getmaskarray(a) for a in x]), **params)
272272
return masked_array(_d, mask=_m)
273+
else:
274+
_d = func(np.asarray(x), **params)
275+
_m = func(getmaskarray(x), **params)
276+
return masked_array(_d, mask=_m)
273277
else:
274278
arrays = []
275279
args = list(args)

numpy/ma/tests/test_extras.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
nomask, ones, zeros, count
2424
)
2525
from numpy.ma.extras import (
26-
atleast_2d, mr_, dot, polyfit, cov, corrcoef, median, average, unique,
27-
setxor1d, setdiff1d, union1d, intersect1d, in1d, ediff1d,
28-
apply_over_axes, apply_along_axis, compress_nd, compress_rowcols,
26+
atleast_1d, atleast_2d, atleast_3d, mr_, dot, polyfit, cov, corrcoef,
27+
median, average, unique, setxor1d, setdiff1d, union1d, intersect1d, in1d,
28+
ediff1d, apply_over_axes, apply_along_axis, compress_nd, compress_rowcols,
2929
mask_rowcols, clump_masked, clump_unmasked, flatnotmasked_contiguous,
30-
notmasked_contiguous, notmasked_edges, masked_all, masked_all_like
30+
notmasked_contiguous, notmasked_edges, masked_all, masked_all_like,
31+
diagflat
3132
)
3233
import numpy.ma.extras as mae
3334

@@ -1127,6 +1128,25 @@ def test_atleast2d(self):
11271128
assert_equal(a.shape, (3,))
11281129
assert_equal(a.mask.shape, a.data.shape)
11291130

1131+
def test_shape_scalar(self):
1132+
# the atleast and diagflat function should work with scalars
1133+
# GitHub issue #3367
1134+
b = atleast_1d(1.0)
1135+
assert_equal(b.shape, (1, ))
1136+
assert_equal(b.mask.shape, b.data.shape)
1137+
1138+
b = atleast_2d(1.0)
1139+
assert_equal(b.shape, (1, 1))
1140+
assert_equal(b.mask.shape, b.data.shape)
1141+
1142+
b = atleast_3d(1.0)
1143+
assert_equal(b.shape, (1, 1, 1))
1144+
assert_equal(b.mask.shape, b.data.shape)
1145+
1146+
b = diagflat(1.0)
1147+
assert_equal(b.shape, (1, 1))
1148+
assert_equal(b.mask.shape, b.data.shape)
1149+
11301150

11311151
if __name__ == "__main__":
11321152
run_module_suite()

0 commit comments

Comments
 (0)
0