Skip to content

BUG: any/all not returning booleans for object type #41102

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

Merged
merged 8 commits into from
May 6, 2021

Conversation

mzeitlin11
Copy link
Member

Also allows removing some of the any/all specific boolean conversion logic in frame reduction code, which (hopefully) also fixes part of #41079.

@mzeitlin11 mzeitlin11 added Bug Reduction Operations sum, mean, min, max, etc. labels Apr 22, 2021
@@ -486,6 +486,12 @@ def nanany(
False
"""
values, _, _, _, _ = _get_values(values, skipna, fill_value=False, mask=mask)

# For object type, any won't necessarily return
Copy link
Contributor

Choose a reason for hiding this comment

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

can you do this in _get_values?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now _get_values is unaware of the nanop it is being used for, so would need slight refactoring to allow that.

While the current solution duplicates the workaround, I like it better than adding in _get_values since this workaround only affects any/all. I think keeping this weird condition out of a path all other nanops hit makes sense.

assert_bool_op_api(
opname, bool_frame_with_na, float_string_frame, has_bool_only=True
)

@pytest.mark.xfail(reason="GH12863: numpy result won't match for object type")
@pytest.mark.parametrize("opname", ["any", "all"])
Copy link
Contributor

Choose a reason for hiding this comment

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

so this is trying to match numpy? do we need this anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

I doubt the original purpose was matching numpy, probably more for adding tests without having to hardcode an expected result. For now I modified this slightly to remove the need for the xfail, but probably could be removed (there's coverage, but it's scattered).

@@ -1108,6 +1112,23 @@ def test_any_all_extra(self):
result = df[["C"]].all(axis=None).item()
assert result is True

@pytest.mark.parametrize("axis", [0, 1])
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have testing of the skipna=True

Copy link
Member Author

Choose a reason for hiding this comment

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

Some scattered testing elsewhere, added skipna parameterization in this test

@@ -270,6 +270,7 @@ def _badobj_wrap(self, value, func, allow_complex=True, **kwargs):
value = value.astype("f8")
return func(value, **kwargs)

@pytest.mark.xfail(reason="GH12863: numpy result won't match for object type")
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this ? (same reason above)

Copy link
Member Author

Choose a reason for hiding this comment

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

Similar response - think more for coverage than matching numpy. Since the nanop gets indirectly tested for all other any/all reductions, I think it could be removed

@jreback jreback added this to the 1.3 milestone May 6, 2021
@jreback jreback merged commit fd3e205 into pandas-dev:master May 6, 2021
@jreback
Copy link
Contributor

jreback commented May 6, 2021

thanks @mzeitlin11

@mzeitlin11 mzeitlin11 deleted the any_all_object_type branch May 6, 2021 04:33
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reduction Operations sum, mean, min, max, etc.
Projects
None yet
2 participants