-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Implement NaT properties/methods directly #17765
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bf54f80
implement nat methods/properties directoly add test
jbrockmendel 727f6ba
Merge branch 'master' of https://github.com/pandas-dev/pandas into ts…
jbrockmendel fd788fe
flake8 whitespace fixup
jbrockmendel b65b3a0
comments per reviewer request
jbrockmendel 7a272f5
amend some NaT error funcs to have empty docstrings to match Timestamp
jbrockmendel 330616b
Pin methods+properties to NaTType instead of _NaT
jbrockmendel c4f4ab5
dummy commit to force CI
jbrockmendel 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 |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
from pandas.util import testing as tm | ||
from pandas._libs.tslib import iNaT | ||
|
||
from pandas.compat import callable | ||
|
||
|
||
@pytest.mark.parametrize('nat, idx', [(Timestamp('NaT'), DatetimeIndex), | ||
(Timedelta('NaT'), TimedeltaIndex), | ||
|
@@ -156,6 +158,53 @@ def test_NaT_methods(): | |
assert NaT.isoformat() == 'NaT' | ||
|
||
|
||
def test_NaT_docstrings(): | ||
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. add the issue number as a comment |
||
# GH#17327 | ||
nat_names = dir(NaT) | ||
|
||
# NaT should have *most* of the Timestamp methods, with matching | ||
# docstrings. The attributes that are not expected to be present in NaT | ||
# are private methods plus `ts_expected` below. | ||
ts_names = dir(Timestamp) | ||
ts_missing = [x for x in ts_names if x not in nat_names and | ||
not x.startswith('_')] | ||
ts_missing.sort() | ||
ts_expected = ['freqstr', 'normalize', 'offset', | ||
'to_julian_date', 'to_period', 'tz'] | ||
assert ts_missing == ts_expected | ||
|
||
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. give a comment before each 'section' of the test so a future reader gets what you are testing |
||
ts_overlap = [x for x in nat_names if x in ts_names and | ||
not x.startswith('_') and | ||
callable(getattr(Timestamp, x))] | ||
for name in ts_overlap: | ||
tsdoc = getattr(Timestamp, name).__doc__ | ||
natdoc = getattr(NaT, name).__doc__ | ||
assert tsdoc == natdoc | ||
|
||
# NaT should have *most* of the Timedelta methods, with matching | ||
# docstrings. The attributes that are not expected to be present in NaT | ||
# are private methods plus `td_expected` below. | ||
# For methods that are both Timestamp and Timedelta methods, the | ||
# Timestamp docstring takes priority. | ||
td_names = dir(Timedelta) | ||
td_missing = [x for x in td_names if x not in nat_names and | ||
not x.startswith('_')] | ||
td_missing.sort() | ||
td_expected = ['components', 'delta', 'is_populated', | ||
'to_pytimedelta', 'to_timedelta64', 'view'] | ||
assert td_missing == td_expected | ||
|
||
td_overlap = [x for x in nat_names if x in td_names and | ||
x not in ts_names and # Timestamp __doc__ takes priority | ||
not x.startswith('_') and | ||
callable(getattr(Timedelta, x))] | ||
assert td_overlap == ['total_seconds'] | ||
for name in td_overlap: | ||
tddoc = getattr(Timedelta, name).__doc__ | ||
natdoc = getattr(NaT, name).__doc__ | ||
assert tddoc == natdoc | ||
|
||
|
||
@pytest.mark.parametrize('klass', [Timestamp, Timedelta]) | ||
def test_isoformat(klass): | ||
|
||
|
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.
these are not defined directly in
Timestamp/_Timestamp
rather directly indatetime.datetime
, maybe direct to there? (I don't know where its actually defined, nor why the inheritence messes this up)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.
They are defined in Timestamp and have empty docstrings there. No idea why. Will add to todo list.
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.
ok great.