-
Notifications
You must be signed in to change notification settings - Fork 35
Add initial pandas 3 support #844
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?
Changes from all commits
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,6 @@ | |||||||||
| import re | ||||||||||
| from pathlib import Path | ||||||||||
|
|
||||||||||
| import numpy as np | ||||||||||
| import pandas as pd | ||||||||||
|
|
||||||||||
| from subscript import getLogger | ||||||||||
|
|
@@ -431,20 +430,25 @@ def compute_date_from_days( | |||||||||
| to this starttime, and converted to DATE. | ||||||||||
|
|
||||||||||
| Returns: | ||||||||||
| pd.DataFrame. DATE column is always of type datetime64 | ||||||||||
| pd.DataFrame. DATE column is always datetime-like | ||||||||||
| (datetime64 unit depends on pandas) | ||||||||||
| """ | ||||||||||
| assert isinstance(dframe, pd.DataFrame) | ||||||||||
| if starttime and "DAYS" in dframe: | ||||||||||
| if "DATE" not in dframe: | ||||||||||
| dframe["DATE"] = np.nan | ||||||||||
| start = pd.to_datetime(starttime) | ||||||||||
| date_needed_rows = ~dframe["DAYS"].isna() & dframe["DATE"].isna() | ||||||||||
| dframe["DATE"] = pd.to_datetime(dframe["DATE"]) | ||||||||||
| dframe.loc[date_needed_rows, "DATE"] = start + pd.to_timedelta( | ||||||||||
| dframe.loc[date_needed_rows, "DAYS"], "d" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| if "DATE" in dframe: | ||||||||||
| dframe["DATE"] = pd.to_datetime(dframe["DATE"]) | ||||||||||
|
|
||||||||||
| if not starttime or "DAYS" not in dframe: | ||||||||||
| return dframe | ||||||||||
|
|
||||||||||
| start = pd.to_datetime(starttime) | ||||||||||
| computed_dates = start + pd.to_timedelta(dframe["DAYS"], unit="D") | ||||||||||
|
||||||||||
| computed_dates = start + pd.to_timedelta(dframe["DAYS"], unit="D") | |
| computed_dates = (start + pd.to_timedelta(dframe["DAYS"], unit="D")).where( | |
| dframe["DAYS"].notna() | |
| ) |
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.
The docstring update mentions that 'datetime64 unit depends on pandas' but this is imprecise. Consider clarifying whether this refers to the resolution (e.g., ns vs. us) and documenting which pandas versions use which units, or stating that the specific unit should not be relied upon by consumers of this function.