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

Fix bug due to pandas release #359

merged 2 commits into from
Jan 26, 2022

Conversation

fealho
Copy link
Member

@fealho fealho commented Jan 25, 2022

Resolves #358 by converting all null-like values to np.nan in the _get_intervals method.

@codecov-commenter
Copy link

codecov-commenter commented Jan 25, 2022

Codecov Report

Merging #359 (25f0278) into master (40d2667) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #359   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           12        12           
  Lines          953       954    +1     
=========================================
+ Hits           953       954    +1     
Impacted Files Coverage Δ
rdt/transformers/categorical.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 40d2667...25f0278. Read the comment docs.

@fealho fealho marked this pull request as ready for review January 25, 2022 04:45
@fealho fealho requested a review from a team as a code owner January 25, 2022 04:45
@@ -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

Copy link
Contributor

@amontanez24 amontanez24 left a comment

Choose a reason for hiding this comment

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

I think maybe we can remove some lines but besides that LGTM!

@@ -89,6 +89,7 @@ def _get_intervals(data):
dict:
intervals for each categorical value (start, end).
"""
data = data.fillna(np.nan)
frequencies = data.value_counts(dropna=False)

start = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. Check #360.

@fealho fealho merged commit adc2b1a into master Jan 26, 2022
@fealho fealho deleted the issue-358-pandas-release-bug branch January 26, 2022 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pandas 1.4.0 release causes a small error
3 participants