-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
API: to_datetime(ints, unit) give requested unit #63347
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
base: main
Are you sure you want to change the base?
Conversation
jorisvandenbossche
left a comment
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.
Looks good!
| errors=errors, | ||
| unit_for_numerics=unit, | ||
| creso=cast(int, NpyDatetimeUnit.NPY_FR_ns.value), | ||
| # creso=cast(int, NpyDatetimeUnit.NPY_FR_ns.value), |
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.
cleanup?
| >>> pd.to_datetime([1, 2, 3], unit="D", origin=pd.Timestamp("1960-01-01")) | ||
| DatetimeIndex(['1960-01-02', '1960-01-03', '1960-01-04'], | ||
| dtype='datetime64[ns]', freq=None) | ||
| dtype='datetime64[s]', freq=None) |
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.
This makes me wonder about a potential corner case: what if the original actually has values for a lower resolution, like actual microseconds or nanoseconds?
| # Without this as_unit cast, we would fail to overflow | ||
| # and get much-too-large dates | ||
| return to_datetime(new_data, errors="raise", unit=date_unit).dt.as_unit( | ||
| "ns" |
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 am not directly understanding that comment. new_data are integers here? Why does the return unit of this function need to be nanoseconds? (to preserve current functionality?) Why would this give (wrong?) too large dates?
|
|
||
| result = read_json(StringIO(json), typ="series") | ||
| expected = ts.copy() | ||
| expected = ts.copy().dt.as_unit("ns") |
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.
Not for this PR, but so this is another case where we currently return ns unit but could change to use us by default?
|
|
||
| index = pd.MultiIndex( | ||
| levels=[[1, 2, 3], [pd.to_datetime("2000-01-01", unit="ns")]], | ||
| levels=[[1, 2, 3], [pd.to_datetime("2000-01-01", unit="ns").as_unit("ns")]], |
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.
Did this PR change that? (that this no longer returns nanoseconds)
to_datetime analogue of #63303.