Skip to content

Fix ndarray allany #12901

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.18.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ Bug Fixes

- Bug in ``pivot_table`` when ``margins=True`` and ``dropna=True`` where nulls still contributed to margin count (:issue:`12577`)

- Bug in ``Series.any`` and ``Series.all`` for dtype object (:issue:`12863`)
- Bug in ``Series.name`` when ``name`` attribute can be a hashable type (:issue:`12610`)
- Bug in ``.describe()`` resets categorical columns information (:issue:`11558`)
- Bug where ``loffset`` argument was not applied when calling ``resample().count()`` on a timeseries (:issue:`12725`)
Expand Down
10 changes: 8 additions & 2 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,18 @@ def _wrap_results(result, dtype):

def nanany(values, axis=None, skipna=True):
values, mask, dtype, _ = _get_values(values, skipna, False, copy=skipna)
return values.any(axis)
if is_object_dtype(dtype):
return any(values)
else:
return values.any(axis)


def nanall(values, axis=None, skipna=True):
values, mask, dtype, _ = _get_values(values, skipna, True, copy=skipna)
return values.all(axis)
if is_object_dtype(dtype):
return all(values)
else:
return values.all(axis)


@disallow('M8')
Expand Down
23 changes: 19 additions & 4 deletions pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,16 +549,31 @@ def test_all_any(self):

# Alternative types, with implicit 'object' dtype.
s = Series(['abc', True])
self.assertEqual('abc', s.any()) # 'abc' || True => 'abc'
self.assertEqual(True, s.any())
self.assertEqual(True, s.all())
s = Series(['abc', False])
self.assertEqual(True, s.any())
self.assertEqual(False, s.all())

def test_all_any_params(self):
# Check skipna, with implicit 'object' dtype.
s1 = Series([np.nan, True])
s2 = Series([np.nan, False])
self.assertTrue(s1.all(skipna=False)) # nan && True => True
self.assertTrue(s1.all(skipna=True))
self.assertTrue(np.isnan(s2.any(skipna=False))) # nan || False => nan
self.assertTrue(s1.all(skipna=False))
self.assertFalse(s2.all(skipna=False))
self.assertTrue(s2.any(skipna=False))
self.assertFalse(s2.any(skipna=True))
self.assertFalse(s2.all(skipna=True))
s1 = Series([None, True])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would these not be exactly the same? (as np.nan)

s2 = Series([None, False])
self.assertFalse(s1.all(skipna=False))
self.assertTrue(s1.any(skipna=False))
self.assertFalse(s2.all(skipna=False))
self.assertFalse(s2.any(skipna=False))
self.assertTrue(s1.all(skipna=True))
self.assertFalse(s2.all(skipna=True))
self.assertFalse(s2.any(skipna=False))


# Check level.
s = pd.Series([False, False, True, True, False, True],
Expand Down