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

Add UniformEncoder (and its ordered version) #681

Merged
merged 10 commits into from
Aug 14, 2023

Conversation

R-Palazzo
Copy link
Contributor

@R-Palazzo R-Palazzo commented Aug 10, 2023

Resolve #678
Compared to the other version, a few changes were necessary in order to:

  • get 100% coverage (2 lines were missing)
  • make the minimum version works.
  • make the uniform encoder works with pd.category dtype

In this PR, the UniformEncoder is set to be the default transformer for categorical and boolean data.
The 1st commit is only moving the files, the other ones made the fixes to make it work on RDT

@R-Palazzo R-Palazzo requested a review from a team as a code owner August 10, 2023 15:14
@R-Palazzo R-Palazzo removed the request for review from a team August 10, 2023 15:14
Copy link
Member

@fealho fealho left a comment

Choose a reason for hiding this comment

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

Looking good, a few comments/questions.

from rdt.transformers.numerical import ClusterBasedNormalizer

SANDBOX_TRANSFORMERS = [ClusterBasedNormalizer, OrderedLabelEncoder, CustomLabelEncoder]
SANDBOX_TRANSFORMERS = [
ClusterBasedNormalizer, OrderedLabelEncoder, CustomLabelEncoder, OrderedUniformEncoder
Copy link
Member

Choose a reason for hiding this comment

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

Why does OrderedUniformEncoder need to be sandboxed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because otherwise the perfomance workflow is crashing with this type error:
FAILED tests/performance/test_performance.py::test_performance[OrderedUniformEncoder-UniqueStringNaNsGenerator] - TypeError: __init__() missing 1 required positional argument: 'order'
I think this is the same reason why the OrderedLabelEncoder is sandboxed

transformer = OrderedUniformEncoder(order=[2, 1])

# Run / Assert
transformer._fit(data)
Copy link
Member

Choose a reason for hiding this comment

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

I think it makes sense to move the _fit/_transform into their own test and leave this one as it was, otherwise this one gets confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I agree, reverted the change in df0ad68.

# Setup
data = pd.Series([1, 2, 3, 2, np.nan, 1, 1])
transformer = OrderedUniformEncoder(order=[2, 3, np.nan, 1])
data = pd.Series([1, 2, 3, 2, None, 1, 1])
Copy link
Member

Choose a reason for hiding this comment

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

Why did you change this to None instead of np.nan?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes that was not necessary at the end haha good catch, reverted in df0ad68

@@ -264,7 +264,10 @@ def _fit(self, data):
else:
freq = data.value_counts(normalize=True, dropna=False)

nan_value = freq[np.nan] if np.nan in freq.index else None
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this works with other types of nans, like float('nan')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe but this should not happen because freq is defined by data.value_counts(), no?

Copy link
Member

Choose a reason for hiding this comment

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

I was concerned with the freq.index having nans in there which are not np.nan. I'm not sure if it's impossible for that to happen.

@codecov-commenter
Copy link

codecov-commenter commented Aug 10, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (74f20ac) 100.00% compared to head (712fe62) 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##            master      #681    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           17        17            
  Lines         1660      1774   +114     
==========================================
+ Hits          1660      1774   +114     
Files Changed Coverage Δ
rdt/transformers/__init__.py 100.00% <ø> (ø)
rdt/transformers/categorical.py 100.00% <100.00%> (ø)
rdt/transformers/utils.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@R-Palazzo
Copy link
Contributor Author

Thanks for your review @fealho ;)

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.

LGTM!

@fealho fealho self-requested a review August 14, 2023 16:50
Copy link
Member

@fealho fealho left a comment

Choose a reason for hiding this comment

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

Thanks for addressing 👍

@R-Palazzo R-Palazzo merged commit d7dccc9 into master Aug 14, 2023
46 checks passed
@R-Palazzo R-Palazzo deleted the issue-678-add-uniform-encoder branch August 14, 2023 16:56
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.

Add UniformEncoder (and its ordered version)
4 participants