narwhals-dev / narwhals

Lightweight and extensible compatibility layer between dataframe libraries!
https://narwhals-dev.github.io/narwhals/
MIT License
349 stars 49 forks source link

Add `.name.suffix` #130

Closed MarcoGorelli closed 1 month ago

MarcoGorelli commented 3 months ago

From a request here

FBruzzesi commented 3 months ago

I have implementation for most methods in the name namespace, however there might be an issue: PandasSeries already defines a name property which makes impossible to register the namespace 😕

MarcoGorelli commented 3 months ago

wow, I'm impressed!

🤔 doesn't polars.Series also have that? https://github.com/pola-rs/polars/blob/11fe9d8f223d50b5e3284b924bb969049b0be6c6/py-polars/polars/series/series.py#L589-L590

I think .name.suffix should only go on expressions, not series, right?

perhaps take a look at .alias, that's fairly similar

FBruzzesi commented 3 months ago

Oh I see, instead of defining the methods on series and then register them, it is enough to define them in the PandasExpr

MarcoGorelli commented 3 months ago

yeah, exactly! the register function is just a trick which allows you to reuse the Series implementation. register_expression_call isn't a good function name to be fair...reuse_series_implementation might be better?

FBruzzesi commented 3 months ago

I am a bit uncertain of a detail, I will open a PR so that we can discuss with code on hand :)