Skip to content
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

Fix bug due to pandas release #359

Merged
merged 2 commits into from
Jan 26, 2022
Merged
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion tests/unit/transformers/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test__get_intervals_nans(self):
categorical value (start, end).
"""
# Setup
data = pd.Series(['foo', np.nan, None, 'foo', 'foo', 'tar'])
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change the expected value instead of this part? I think it's good to know how this function handles None

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't really do it, since there are two distinct behaviors for this input, depending on what version of pandas we are running. For pandas 1.4.0, the existing code doesn't even work on this input. Notice that the categorical transformer does the following:

if pd.isna(value):
value = np.nan
intervals[value] = (start, end, mean, std)

So we actually just overwrite the first np.nan with the None, which is not the intended behavior. If we do want to keep support for multiple types of nan's, we could cast all null objects no np.nan right at the start of the function.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's weird that value__counts doesn't treat None as np.nan, but pd.isna will still return True for it. My question is, is it possible for _get_intervals to receive data with different null types. If so, we have to handle that which means I think we should convert them all before doing the value_counts

data = pd.Series(['foo', np.nan, np.nan, 'foo', 'foo', 'tar'])

# Run
result = CategoricalTransformer._get_intervals(data)
Expand Down