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

feat: Series descriptive methods #187

Merged
merged 6 commits into from
May 20, 2024
Merged

feat: Series descriptive methods #187

merged 6 commits into from
May 20, 2024

Conversation

FBruzzesi
Copy link
Member

@FBruzzesi FBruzzesi commented May 18, 2024

Description

Similar to #159 but for series and expr methods (complete list from polars); introduces the following Series methods:

  • is_duplicated
  • is_empty (not in expr)
  • is_unique
  • null_count
  • is_first_distinct
  • is_last_distinct
  • is_sorted (not in expr)
  • value_counts (not in expr)

@FBruzzesi FBruzzesi requested a review from MarcoGorelli May 18, 2024 14:26
Comment on lines 136 to 138
.difference(
{"to_pandas", "to_numpy", "dtype", "name", "shape", "to_frame", "is_empty"}
)
Copy link
Member Author

@FBruzzesi FBruzzesi May 18, 2024

Choose a reason for hiding this comment

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

Would it make sense to dynamically extract the set of methods that a polars Series supports but Expr does not? Something like the following should be enough:

series_only = [
    i for i in dir(pl.Series)
    if not i[0].isupper() and i[0] != "_" and i not in dir(pl.Expr)
]

Let me know what you think

Copy link
Member

Choose a reason for hiding this comment

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

maybe, but there's also value in this being manual, so we can inspect whether it makes sense that a given method is missing

@MarcoGorelli
Copy link
Member

thanks @FBruzzesi ! Looks like value_counts is failing on the minimum pandas version, possibly related to pandas-dev/pandas#49912

@FBruzzesi
Copy link
Member Author

thanks @FBruzzesi ! Looks like value_counts is failing on the minimum pandas version, possibly related to pandas-dev/pandas#49912

Thanks Marco, it seems that both naming and order is different (as if sort=True has no effect?). Should we manually address that? E.g. renaming and sorting afterwards?

@MarcoGorelli
Copy link
Member

I think order is fine, there are other places where the order isn't preserved (e.g. group_by) - shall we just document the lack of ordering guarantee, and fixup the names?

@FBruzzesi
Copy link
Member Author

Pandas value_counts has a sort keyword since forever I think (v1.0 is the furthest I could find on the doc page). Setting sort=True and getting unsorted results is not ideal to me

@MarcoGorelli
Copy link
Member

yeah, sorry, hadn't looked carefully enough - sure, this one should be easy enough to work around and manually fixup

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Wow, absolute legend mate!

I can never remember the is_first_distinct in pandas, so I may need to refer to this if I ever need to write pandas again (and I probably will at some point 😄 )

Just made a minor comment

Approving, though I didn't sleep much tonight (got up early to catch a train) so I'm not super-"with it", feel free to merge if you're confident

"""Parallel is unused, exists for compatibility"""
from narwhals._pandas_like.dataframe import PandasDataFrame

name_ = self._series.name or "index"
Copy link
Member

Choose a reason for hiding this comment

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

if self._series.name is something like 0 or '', will this overwrite it with 'index'? should be specifically check for if self._series.name is 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.

Thanks! That's a great catch 🙈

@FBruzzesi FBruzzesi merged commit f18c533 into main May 20, 2024
16 checks passed
@FBruzzesi FBruzzesi deleted the feat/series-descriptive branch May 20, 2024 14:17
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.

2 participants