-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
API: timestamp resolution inference: default to microseconds when possible #62031
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
Draft
jorisvandenbossche
wants to merge
13
commits into
pandas-dev:main
Choose a base branch
from
jorisvandenbossche:default-us-reso
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+398
−341
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7421077
API: timestamp resolution inference: default to microseconds when pos…
jorisvandenbossche fcb2953
Merge remote-tracking branch 'upstream/main' into default-us-reso
jorisvandenbossche d4a5536
update tests
jorisvandenbossche fd6c6df
fix timestamp replace
jorisvandenbossche c940c86
update indexes / indexing tests
jorisvandenbossche 21954fb
update frame and series tests
jorisvandenbossche 9faa930
update arrays, base, dtypes tests
jorisvandenbossche cf12f9b
update excel tests
jorisvandenbossche ee40976
update groupby / resample / reshape tests
jorisvandenbossche 461ef56
update remaining io tests
jorisvandenbossche c67f1f6
update test_tzlocal_offset
jorisvandenbossche 991c986
Merge remote-tracking branch 'upstream/main' into default-us-reso
jorisvandenbossche e3d7b64
update docstrings
jorisvandenbossche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,21 @@ | |
# originals | ||
from enum import Enum | ||
|
||
import numpy as np | ||
|
||
from cpython.object cimport ( | ||
Py_GE, | ||
Py_LE, | ||
) | ||
|
||
from pandas._libs.tslibs.ccalendar cimport c_MONTH_NUMBERS | ||
from pandas._libs.tslibs.np_datetime cimport ( | ||
NPY_DATETIMEUNIT, | ||
cmp_dtstructs, | ||
get_conversion_factor, | ||
import_pandas_datetime, | ||
npy_datetimestruct, | ||
pandas_datetime_to_datetimestruct, | ||
) | ||
|
||
import_pandas_datetime() | ||
|
@@ -504,6 +514,45 @@ cdef NPY_DATETIMEUNIT get_supported_reso(NPY_DATETIMEUNIT reso): | |
return reso | ||
|
||
|
||
cdef npy_datetimestruct dts_us_min, dts_us_max | ||
pandas_datetime_to_datetimestruct( | ||
np.iinfo(np.int64).min + 1, NPY_DATETIMEUNIT.NPY_FR_us, &dts_us_min | ||
) | ||
pandas_datetime_to_datetimestruct( | ||
np.iinfo(np.int64).max, NPY_DATETIMEUNIT.NPY_FR_us, &dts_us_max | ||
) | ||
|
||
|
||
cdef NPY_DATETIMEUNIT get_supported_reso_for_dts( | ||
NPY_DATETIMEUNIT reso, npy_datetimestruct* dts | ||
): | ||
# Similar as above, but taking the actual datetime value in account, | ||
# defaulting to 'us' if possible. | ||
if reso == NPY_DATETIMEUNIT.NPY_FR_GENERIC: | ||
return NPY_DATETIMEUNIT.NPY_FR_ns | ||
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. should this be FR_us? |
||
# if dts.ps != 0: | ||
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. why are the .ps checks not necessary? |
||
# return NPY_DATETIMEUNIT.NPY_FR_ns | ||
# elif ( | ||
# cmp_dtstructs(dts, &dts_us_min, Py_GE) | ||
# and cmp_dtstructs(dts, &dts_us_max, Py_LE) | ||
# ): | ||
# return NPY_DATETIMEUNIT.NPY_FR_us | ||
# else: | ||
# return NPY_DATETIMEUNIT.NPY_FR_s | ||
if reso < NPY_DATETIMEUNIT.NPY_FR_us: | ||
if ( | ||
cmp_dtstructs(dts, &dts_us_min, Py_GE) | ||
and cmp_dtstructs(dts, &dts_us_max, Py_LE) | ||
): | ||
return NPY_DATETIMEUNIT.NPY_FR_us | ||
else: | ||
# TODO still distinguish between ms or s? | ||
return NPY_DATETIMEUNIT.NPY_FR_s | ||
elif reso > NPY_DATETIMEUNIT.NPY_FR_ns: | ||
return NPY_DATETIMEUNIT.NPY_FR_ns | ||
return reso | ||
|
||
|
||
cdef bint is_supported_unit(NPY_DATETIMEUNIT reso): | ||
return ( | ||
reso == NPY_DATETIMEUNIT.NPY_FR_ns | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
util.INT64_MAX