-
Notifications
You must be signed in to change notification settings - Fork 453
MNT: Make GroupFeature
dataframe agnostic
#1546
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 o 8000 ccasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
MNT: Make GroupFeature
dataframe agnostic
#1546
Conversation
nw_feature_vector = nw.from_native(feature_vector, pass_through=True, allow_series=True) | ||
is_nw_series = isinstance(nw_feature_vector, nw.Series) | ||
|
||
self.classes_ = np.unique(nw_feature_vector) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that self.classes_
is set but unused. If commented out, the only failing tests are those that specifically test for the attribute value
self.raw_feature_ = ( | ||
list(nw_feature_vector) if not is_nw_series else nw_feature_vector.to_list() | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since raw_feature_
is always casted to list in MetricFrame
, I moved that directly here so that for those inputs that are converted to narwhals Series we can use the native to_list
methods
if (name_ := nw_feature_vector.name) is not None: | ||
if isinstance(name_, str): | ||
self.name_ = name_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Polars does not allow None
as series name, but when unnamed, then its name is ""
(empty string), hence that's what self.name_
would be set to.
I didn't put too much thought into this, I just wanted to highlight the behavior
all_data[sf.name_] = list(sf.raw_feature_) | ||
all_data[sf.name_] = sf.raw_feature_ | ||
if cf_list is not None: | ||
for cf in cf_list: | ||
all_data[cf.name_] = list(cf.raw_feature_) | ||
all_data[cf.name_] = cf.raw_feature_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to previous comment
Description
Make
GroupFeature
dataframe agnostic via narwhals.Opening as draft as I have a few questions/remarks (see code comments)
Related to #1522
Tests
Documentation