-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: add fold support to Timestamp constructor #31563
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
Merged
Merged
Changes from 131 commits
Commits
Show all changes
137 commits
Select commit
Hold shift + click to select a range
84bfff2
TST: add basic test for construction with fold
AlexKirko ba7fcd5
ENH: add basic fold support
AlexKirko 0b6f894
ENH: add fold to ts properties
AlexKirko 5c58b3a
baseline fold in conversion
AlexKirko 546789a
add fold placeholder to conversion
AlexKirko fc69bbb
add fold to convert_to_tsobject
AlexKirko 57d42b3
TST: add test to infer fold from value
AlexKirko f2ad196
ENH: infer fold from value for dateutil
AlexKirko 935a3ec
ENH: infer fold for pytz (loss in performance)
AlexKirko d35af8f
PERF: remove unnecessary ifs
AlexKirko e6d4aaa
check that we are not at the left edge of deltas
AlexKirko fd98b27
ENH: adjust Timestamp.value for fold (if not from datetime or string)
AlexKirko af86f79
CLN: remove extra spaces
AlexKirko a6965e9
TST: add test for adjusting value for fold
AlexKirko 4caf9bb
DOC: add to comment for local timezone
AlexKirko 6843ed2
TST: add string case to fold inferring test
AlexKirko ebbf21f
ENH: infer fold for timestamp from string
AlexKirko 4f43638
TST: add fold value adjustment from string
AlexKirko 6238f9b
ENH: adjust value for fold from string
AlexKirko 3584791
basic from datetime fold support with bugs
AlexKirko 237341b
complete adjust value for fold from datetime
AlexKirko 12b8b4e
use input fold as default
AlexKirko 92e990e
TST: adjust datetime for included fold
AlexKirko c2189d3
TST: infer fold from fold included in datetime
AlexKirko 9c9c2dd
FIX: fix bool condition for inferring fold for str
AlexKirko f0bbbcb
remove unnecessary value shift for inferring fold from str
AlexKirko ca46078
remove unnecessary GH24329 fix
AlexKirko 411b036
pass fold through Timstamp.replace
AlexKirko 464dadf
TST:fix ambiguous compatibility test in scalar test_timezones
AlexKirko 2b9f2f6
TST: remove test for ambiguous error near dst boundary
AlexKirko ef87010
DOC: add fold arg description to functions and methods
AlexKirko ecfde58
REFACTOR: remove code duplication in localize_tso
AlexKirko 6970ed1
DOC: add fold description to ints_to_pydatetime
AlexKirko 353e554
REFACTOR: make obj.fold assignment process more transparent
AlexKirko bce8f0d
DOC: clarify comments for fold adjustment and inferring
AlexKirko 558c237
REFACTOR: compact datetime_to_tsobject and refactor checks
AlexKirko 7b88ffd
DOC: clarify comments for datetime_to_tsobject
AlexKirko 9621c0a
add pos shift for adjusting value for fold in localize_tso
AlexKirko 6bf58b5
CLN: remove unnecessary comment
AlexKirko 73364af
try to speed up datetime processing
AlexKirko a8ad96c
Revert "try to speed up datetime processing" - does not work
AlexKirko 104c97d
CLN: remove unnecessary fold assignment in timestamps
AlexKirko 1f9e810
DOC: add whatsnew entry
AlexKirko 55f0b8a
DOC: fix whatsnew
AlexKirko 5e1be83
Merge branch 'master' into add-fold-to-timestamp
AlexKirko bda4934
Merge branch 'master' into add-fold-to-timestamp
AlexKirko 1065085
CLN: finish merging
AlexKirko f9c6956
cut the logic to benchmark function signatures
AlexKirko 62d5d6b
Revert "cut the logic to benchmark function signatures" - return to o…
AlexKirko 6294ee9
PERF: change fold to fold or 0
AlexKirko f13e3d7
CLN: clean up TODOs
AlexKirko eade807
CLN: trim comments, add issues to whatsnew
AlexKirko 7269f9a
fold: set Tiemstamp default to 0, reformat description
AlexKirko d650086
rollback Timestamp fold default to None
AlexKirko 693cb6c
REFACT: move value adjustment for fold to function
AlexKirko 2fe9ce7
REFACT: move inferring fold to a function
AlexKirko 3e2c76c
CLN: remove unnecessary whitespace
AlexKirko 2f4fdda
DOC: trim fold arg description in tslib.pyx
AlexKirko 9f7a16e
REFACT: tighten code in datetime_to_tsobject
AlexKirko a6d37ea
REFACT: set TSObject default fold to 0
AlexKirko a017953
CLN: lint multiline if in datetime_to_tsobject
AlexKirko 1d716e7
TST: reparametrize tests
AlexKirko b47efe0
raise if ts_input.fold and fold do not match
AlexKirko cf7c091
restart tests
AlexKirko a49a7e9
Merge branch 'master' into add-fold-to-timestamp
AlexKirko c39c490
Merge branch 'master' into add-fold-to-timestamp to resolve conflicts
AlexKirko 75e1633
add ambiguous timezone to whatsnew example
AlexKirko 21883be
combine is_utc and is_tzlocal
AlexKirko b21cb47
remove inner parenthesis
AlexKirko 3ca1fc3
combine if statements in Timestamp constructor
AlexKirko edde445
CLN: replace "typ == or typ ==" with "typ in [...]"
AlexKirko d5925af
REFACT: move fold assignment to cdef
AlexKirko b128cde
DOC: add more note and examples for Timestamp.fold
AlexKirko a673b65
add valid fold value check to Timestamp constructor
AlexKirko 276fad7
REFACT: move fold default from _TSObject cinit to explicit
AlexKirko 5540de1
DOC: fix typo in error message
AlexKirko 30eef01
TST: fix the rest of typo
AlexKirko 68b05fc
change raise bahvior to allow overriding naive datetime
AlexKirko d67ec4f
DOC: update localize_tso docstring
AlexKirko 3262085
change override default to raise
AlexKirko 4790b76
finish transition to new behavior
AlexKirko 353bd87
DOC: revert localize_tso docstring
AlexKirko 94e9e65
CLN: remove unnecessary change
AlexKirko a69833a
restore pytz ambiguous test
AlexKirko e58ecb9
CLN: lint the tests
AlexKirko e1ffa8d
set fold in Timestamp.replace after pytz resets it
AlexKirko c57ec65
fix datetime call in docs
AlexKirko f3f8690
fix doc error
AlexKirko 476c4a4
for naive datetime, set default to 0
AlexKirko afaeb88
TST: expand tests
AlexKirko 4a33d36
REFACT: bundle fold in ts_input
AlexKirko 82ed93c
pass fold to func_create candidates in tslib.pyx
AlexKirko d9aea09
remove dateutil adjustment from convert_datetime_to_tsobject
AlexKirko d68efb6
move relevant parts of adjust function where called and drop
AlexKirko 9328071
CLN: revert localize_tso docstring notes
AlexKirko 4ecbaf1
REFACT: combine raise conditions in timestamps.pyx
AlexKirko ee90ac7
CLN: tighten error messages
AlexKirko 25291e4
CLN: black the tests
AlexKirko 08cc256
DOC: expand doc in timeseries.rst and make it a note
AlexKirko 2910720
TST: fix pytz fold conflict test
AlexKirko f6c11da
DOC: improve formatting in timeseries.rst addition
AlexKirko 6f16ea5
DOC: update whatsnew
AlexKirko 5024452
CLN: fix linting mistakes
AlexKirko 3e49b7a
add versionadded where appropriate
AlexKirko bcf0905
DOC: add references to PEP 495
AlexKirko 9b614ae
add local timezone support
AlexKirko 467a11e
Merge branch 'master' into add-fold-to-timestamp
AlexKirko 2145b05
Revert "add local timezone support"
AlexKirko 8f82aa1
make fold keyword-only
AlexKirko d39e811
CLN: prune pytz-specific logic in Timestamp.replace
AlexKirko 3091689
switch from getattr to hasattr in the constructor
AlexKirko 4cfac36
Merge branch 'master' into add-fold-to-timestamp
AlexKirko e58fe0c
ENH: add fold support
AlexKirko d166a67
REFACT: initalize _TSObject.fold to False explicitly
AlexKirko 5729eb8
CLN: fix linting
AlexKirko c9863e1
CLN: remove unnecessary TODOs
AlexKirko 1d72e2d
add comment to __cinit__
AlexKirko 97883ce
try reverting the changes to fix test error
AlexKirko aa5232b
Revert "try reverting the changes to fix test error"
AlexKirko 0ebbe02
REFACT: no longer set delta by pointer
AlexKirko c840fd6
fix linting
AlexKirko a793bb5
DOC: tweak docstrings in tzconversion
AlexKirko 920d52a
Merge branch 'master' into add-fold-to-timestamp
AlexKirko d732139
statically type trans and deltas
AlexKirko 752acbc
REFACT: use PyDateTime_Check when deciding if to raise
AlexKirko a1f69cf
DOC: add refs to docs, add blank lines to docstrings
AlexKirko 97dc342
REFACT: merge replace with error raising in timestamp.pyx
AlexKirko 7ac14df
REFACT: move +/- delta logic out of _tzlocal_get_offset_components
AlexKirko 397b2c8
CLN: fix indentation
AlexKirko 757bd41
DOC: anonimize references
AlexKirko 46a279b
DOC: give descriptive names to refs
AlexKirko 81560bb
DOC: make fold a subsection in timeseries.rst
AlexKirko 4256642
TST: add test for invalid fold raise
AlexKirko a24594a
Merge branch 'master' into add-fold-to-timestamp
AlexKirko 0168aa6
DOC: rephrase text in timeseries.rst to improve readability
AlexKirko 3a605c3
Merge branch 'master' into add-fold-to-timestamp
AlexKirko cd02318
add fold support to merged code
AlexKirko 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,28 @@ For example: | |
ser["2014"] | ||
ser.loc["May 2015"] | ||
|
||
.. _whatsnew_110.timestamp_fold_support: | ||
|
||
Fold argument support in Timestamp constructor | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
:class:`Timestamp:` now supports the keyword-only fold argument according to `PEP 495 <https://www.python.org/dev/peps/pep-0495/#the-fold-attribute>`_ similar to parent ``datetime.datetime`` class. It supports both accepting fold as an initialization argument and inferring fold from other constructor arguments (:issue:`25057`, :issue:`31338`). Support is limited to ``dateutil`` timezones as ``pytz`` doesn't support fold. | ||
|
||
For example: | ||
|
||
.. ipython:: python | ||
|
||
ts = pd.Timestamp("2019-10-27 01:30:00+00:00") | ||
ts.fold | ||
|
||
.. ipython:: python | ||
|
||
ts = pd.Timestamp(year=2019, month=10, day=27, hour=1, minute=30, | ||
tz="dateutil/Europe/London", fold=1) | ||
ts | ||
|
||
For more, see :ref:`Timezone section <timeseries.timezone>` in the user guide on working with timezones. | ||
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. reference the sub-section here 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. Done. |
||
|
||
.. _whatsnew_110.enhancements.other: | ||
|
||
Other enhancements | ||
|
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.
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.
let's make this a sub-section (e.g. Fold), add a reference (so you can link to it in whatsnew)
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.
should be the same level as working with time zones
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.
Done.