-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: change object-array comparisons to prefer OO->O unfuncs #14800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Comparison on ``object`` dtypes will prefer ``object`` output | ||
------------------------------------------------------------- | ||
Comparison ufuncs (``np.equal`` and friends) would return boolean arrays when | ||
the input array dtype was ``object``. This led to inconsistent behaviour for | ||
ragged arrays ``a = np.array([1, np.array([1, 2, 3])], dtype=object)``. This | ||
will now return an object array:: | ||
|
||
>>> a = np.array([1, np.array([1, 2, 3])], dtype=object) | ||
>>> np.equal(a, a) | ||
array([True, array([ True, True, True])], dtype=object) | ||
|
||
The old behaviour, which will raise a ``ValueError`` in this case, is still | ||
available by specifying a dtype as ``np.equal(a, a, dtype=bool)``. | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -172,10 +172,11 @@ def test_normal_types(self): | |||||
# (warning is issued a couple of times here) | ||||||
self.assert_deprecated(op, args=(a, a[:-1]), num=None) | ||||||
|
||||||
# Element comparison error (numpy array can't be compared). | ||||||
# ragged array comparison returns True/False | ||||||
a = np.array([1, np.array([1,2,3])], dtype=object) | ||||||
b = np.array([1, np.array([1,2,3])], dtype=object) | ||||||
self.assert_deprecated(op, args=(a, b), num=None) | ||||||
res = op(a, b) | ||||||
assert res.dtype == 'object' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This now returns an object array instead of deprecating. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
def test_string(self): | ||||||
# For two string arrays, strings always raised the broadcasting error: | ||||||
|
F438
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4790,7 +4790,12 @@ def all(self, axis=None, out=None, keepdims=np._NoValue): | |
|
||
mask = _check_mask_axis(self._mask, axis, **kwargs) | ||
if out is None: | ||
d = self.filled(True).all(axis=axis, **kwargs).view(type(self)) | ||
r = self.filled(True).all(axis=axis, **kwargs) | ||
# object dtypes with axis=None return a scalar | ||
if isinstance(r, bool): | ||
d = type(self)(r) | ||
else: | ||
d = r.view(type(self)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, could pass |
||
if d.ndim: | ||
d.__setmask__(mask) | ||
elif mask: | ||
|
Uh oh!
There was an error while loading. Please reload this page.