Skip to content

Commit

Permalink
BUG: Pandas any() returning false with true values present (GH pandas…
Browse files Browse the repository at this point in the history
  • Loading branch information
makbigc authored and jreback committed Dec 30, 2018
1 parent 460945e commit 36ab8c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ Timezones
- Bug in :class:`Timestamp` constructor where a ``dateutil.tz.tzutc`` timezone passed with a ``datetime.datetime`` argument would be converted to a ``pytz.UTC`` timezone (:issue:`23807`)
- Bug in :func:`to_datetime` where ``utc=True`` was not respected when specifying a ``unit`` and ``errors='ignore'`` (:issue:`23758`)
- Bug in :func:`to_datetime` where ``utc=True`` was not respected when passing a :class:`Timestamp` (:issue:`24415`)
- Bug in :meth:`DataFrame.any` returns wrong value when ``axis=1`` and the data is of datetimelike type (:issue:`23070`)

Offsets
^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7291,7 +7291,7 @@ def f(x):
if filter_type is None or filter_type == 'numeric':
data = self._get_numeric_data()
elif filter_type == 'bool':
data = self._get_bool_data()
data = self
else: # pragma: no cover
msg = ("Generating numeric_only data with filter_type {f}"
"not supported.".format(f=filter_type))
Expand Down
38 changes: 14 additions & 24 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,6 @@ def assert_bool_op_api(opname, bool_frame_with_na, float_string_frame,
getattr(mixed, opname)(axis=0)
getattr(mixed, opname)(axis=1)

class NonzeroFail(object):

def __nonzero__(self):
raise ValueError

mixed['_nonzero_fail_'] = NonzeroFail()

if has_bool_only:
getattr(mixed, opname)(axis=0, bool_only=True)
getattr(mixed, opname)(axis=1, bool_only=True)
Expand Down Expand Up @@ -1374,25 +1367,22 @@ def test_any_all_extra(self):
result = df[['C']].all(axis=None).item()
assert result is True

# skip pathological failure cases
# class CantNonzero(object):

# def __nonzero__(self):
# raise ValueError
def test_any_datetime(self):

# df[4] = CantNonzero()

# it works!
# df.any(1)
# df.all(1)
# df.any(1, bool_only=True)
# df.all(1, bool_only=True)
# GH 23070
float_data = [1, np.nan, 3, np.nan]
datetime_data = [pd.Timestamp('1960-02-15'),
pd.Timestamp('1960-02-16'),
pd.NaT,
pd.NaT]
df = DataFrame({
"A": float_data,
"B": datetime_data
})

# df[4][4] = np.nan
# df.any(1)
# df.all(1)
# df.any(1, bool_only=True)
# df.all(1, bool_only=True)
result = df.any(1)
expected = Series([True, True, True, False])
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize('func, data, expected', [
(np.any, {}, False),
Expand Down

0 comments on commit 36ab8c9

Please sign in to comment.