-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: non-nano datetime64s for read_sas #56127
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
Changes from 11 commits
c9bad87
1308f01
5f0d452
0aedc45
ba467d2
74b6016
ffa80ba
ea48931
a844d64
cebf6ca
87b3eaf
2896163
e3aeae2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,7 @@ | |
timedelta, | ||
) | ||
import sys | ||
from typing import ( | ||
TYPE_CHECKING, | ||
cast, | ||
) | ||
from typing import TYPE_CHECKING | ||
|
||
import numpy as np | ||
|
||
|
@@ -39,14 +36,13 @@ | |
Parser, | ||
get_subheader_index, | ||
) | ||
from pandas.errors import ( | ||
EmptyDataError, | ||
OutOfBoundsDatetime, | ||
) | ||
from pandas._libs.tslibs.conversion import cast_from_unit_vectorized | ||
from pandas.errors import EmptyDataError | ||
|
||
import pandas as pd | ||
from pandas import ( | ||
DataFrame, | ||
Timestamp, | ||
isna, | ||
) | ||
|
||
|
@@ -62,6 +58,10 @@ | |
) | ||
|
||
|
||
_unix_origin = Timestamp("1970-01-01") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will these be reused in the future? Otherwise could just inline the 10 year timedelta in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. either way. i think this is nicely clear about where the 10 year difference stems from (also cant do Timedelta(years=10)) |
||
_sas_origin = Timestamp("1960-01-01") | ||
|
||
|
||
def _parse_datetime(sas_datetime: float, unit: str): | ||
if isna(sas_datetime): | ||
return pd.NaT | ||
|
@@ -94,12 +94,16 @@ def _convert_datetimes(sas_datetimes: pd.Series, unit: str) -> pd.Series: | |
Series | ||
Series of datetime64 dtype or datetime.datetime. | ||
""" | ||
try: | ||
return pd.to_datetime(sas_datetimes, unit=unit, origin="1960-01-01") | ||
except OutOfBoundsDatetime: | ||
s_series = sas_datetimes.apply(_parse_datetime, unit=unit) | ||
s_series = cast(pd.Series, s_series) | ||
return s_series | ||
td = (_sas_origin - _unix_origin).as_unit("s") | ||
if unit == "s": | ||
millis = cast_from_unit_vectorized( | ||
sas_datetimes._values, unit="s", out_unit="ms" | ||
) | ||
dt64ms = millis.view("M8[ms]") + td | ||
return pd.Series(dt64ms, index=sas_datetimes.index) | ||
else: | ||
vals = np.array(sas_datetimes, dtype="M8[D]") + td | ||
return pd.Series(vals, dtype="M8[s]", index=sas_datetimes.index) | ||
|
||
|
||
class _Column: | ||
|
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.
?