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

[Enh]: ncs.datetime selector #1813

Open
davidhopkinson26 opened this issue Jan 15, 2025 · 2 comments
Open

[Enh]: ncs.datetime selector #1813

davidhopkinson26 opened this issue Jan 15, 2025 · 2 comments

Comments

@davidhopkinson26
Copy link

davidhopkinson26 commented Jan 15, 2025

We would like to learn about your use case. For example, if this feature is needed to adopt Narwhals in an open source project, could you please enter the link to it below?

use case for this came up in this PR of tubular lvgig/tubular#366.

Please describe the purpose of the new feature or describe the problem to solve.

We want to select all datetime columns and currently have to define all of these:

TIME_UNITS = ["us", "ns", "ms"]
TIME_ZONES = zoneinfo.available_timezones().union({None})

DATETIME_VARIANTS = [
nw.Datetime(time_unit=time_unit, time_zone=time_zone)
for time_unit in TIME_UNITS
for time_zone in TIME_ZONES
]

datetime_columns = list(
X.select(ncs.by_dtype(*DATETIME_VARIANTS)).columns,)

Suggest a solution if possible.

I expect similar logic could be turned into an ncs.datetime selector function similar to current categorical/numeric.

If you have tried alternatives, please describe them below.

No response

Additional information that may help us understand your needs.

No response

@FBruzzesi
Copy link
Member

FBruzzesi commented Jan 15, 2025

Hey @davidhopkinson26 thanks for requesting this feature. This might be a duplicate of #1313, but it should be possible to make a dedicated datetime selector which is not built through nw.selectors.by_dtype

@davidhopkinson26
Copy link
Author

Thanks for pointing out the similar ticket @FBruzzesi. Yes I am asking for a replication of pl.selectors.datetime functionality into narwhals rather than using by_dtype driectly. https://docs.pola.rs/api/python/stable/reference/selectors.html#polars.selectors.datetime

#1313 appears to be about unexpected behaviour in by_dtype when passing datetime types. So that probably needs addressing first since a dedicated selector would presumably wrap by_dtype?

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

No branches or pull requests

2 participants