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

disallow casting temporal to integer #121

Open
MarcoGorelli opened this issue May 9, 2024 · 4 comments · May be fixed by #1654
Open

disallow casting temporal to integer #121

MarcoGorelli opened this issue May 9, 2024 · 4 comments · May be fixed by #1654
Assignees

Comments

@MarcoGorelli
Copy link
Member

in pandas this does something really strange

In [3]: pd.to_datetime(['2020', None]).astype('int64')
Out[3]: Index([1577836800000000000, -9223372036854775808], dtype='int64')

Users shouldn't be relying on phyisical representations anyway, we should nudge them towards .dt.microseconds or whatever it is they're looking for

@FBruzzesi
Copy link
Member

FBruzzesi commented Sep 12, 2024

Polars seems to allow it, except null is preserved, is that what you mean to ban?

from datetime import datetime
import polars as pl

pl.Series([
    datetime(year=2020, month=1, day=1, hour=0, second=0, minute=0),
    None
]).cast(pl.Int64)
shape: (2,)
Series: '' [i64]
[
        1577836800000000
        null
]

@MarcoGorelli
Copy link
Member Author

yeah I think so, I think it'd be better to nudge people towards .dt.timestamp / .dt.microsecond / etc. depending on which they want, it should be more robust than casting

@DeaMariaLeon
Copy link
Member

Do we still want this?

@MarcoGorelli
Copy link
Member Author

yes I think we should raise where possible when trying to cast a datetime to a numeric type. At least for pandas-like and PyArrow (those are the ones people are most likely to test, so if they find that it raises in those cases, they'll be less likely to use it)

@DeaMariaLeon DeaMariaLeon self-assigned this Dec 22, 2024
@DeaMariaLeon DeaMariaLeon linked a pull request Dec 23, 2024 that will close this issue
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants