8000 ENH: np.angle: Preserve subclasses · convexset/numpy@aea9eb2 · GitHub
[go: up one dir, main page]

Skip to content

Commit aea9eb2

Browse files
committed
ENH: np.angle: Preserve subclasses
1 parent e7a0f75 commit aea9eb2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

numpy/lib/function_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ def angle(z, deg=False):
13391339
45.0
13401340
13411341
"""
1342-
z = asarray(z)
1342+
z = asanyarray(z)
13431343
if issubclass(z.dtype.type, _nx.complexfloating):
13441344
zimag = z.imag
13451345
zreal = z.real

numpy/lib/tests/test_function_base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,16 @@ def test_basic(self):
10431043
assert_array_almost_equal(y, yo, 11)
10441044
assert_array_almost_equal(z, zo, 11)
10451045

1046+
def test_subclass(self):
1047+
x = np.ma.array([1 + 3j, 1, np.sqrt(2)/2 * (1 + 1j)])
1048+
x[1] = np.ma.masked
1049+
< 6D17 span class=pl-s1>expected = np.ma.array([np.arctan(3.0 / 1.0), 0, np.arctan(1.0)])
1050+
expected[1] = np.ma.masked
1051+
actual = angle(x)
1052+
assert_equal(type(actual), type(expected))
1053+
assert_equal(actual.mask, expected.mask)
1054+
assert_equal(actual, expected)
1055+
10461056

10471057
class TestTrimZeros(object):
10481058

0 commit comments

Comments
 (0)
0