-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
TST: resolve issues with test_constructor_dtype_datetime64 #24868
Conversation
@@ -688,10 +688,21 @@ def test_constructor_dtype_datetime64(self): | |||
pytest.raises(TypeError, lambda x: Series( | |||
Series(dates).astype('int') / 1000000, dtype='M8[ms]')) | |||
|
|||
msg = (r"The 'datetime64' dtype has no unit\. Please pass in" |
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.
Hmm is this not intentional to have around still?
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.
this is explicitly tested by test_astype_generic_timestamp_no_frequency
. however i've now updated this test so that the error message check is more explicit.
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.
i'm guessing that the intended error message for this test would have been originally that raised by
pandas/pandas/core/dtypes/cast.py
Lines 644 to 646 in af82b2a
raise TypeError("cannot astype a datetimelike from [{from_dtype}] " | |
"to [{to_dtype}]".format(from_dtype=arr.dtype, | |
to_dtype=dtype)) |
and before the conversion to pytest.raises context manager the test was
pandas/pandas/tests/series/test_constructors.py
Lines 680 to 681 in 17a6bc5
pytest.raises(TypeError, | |
lambda x: Series(dates, dtype='datetime64')) |
which would have been raising TypeError: missing 1 required positional argument: 'x'
since there was no message check the tested function raising TypeError
would have incorrectly been considered a test pass
so this test was never intended to test for The 'datetime64' dtype has no unit
message.
hope that makes it clear!
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.
so I DO want this test to remain, can you simply change it so it is testing with dtype='datetime64'
, IOW it raises.
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.
This might actually be a duplicate test (if so, then can remove)
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.
so I DO want this test to remain, can you simply change it so it is testing with
dtype='datetime64'
, IOW it raises.
This might actually be a duplicate test (if so, then can remove)
testing with dtype='datetime64'
is explicitly tested by another test: test_astype_generic_timestamp_no_frequency
.
however within this PR i've also changed test_astype_generic_timestamp_no_frequency
so that the error message check is more explicit so that it could be removed here.
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, you are going to remove this test? rather, this case?
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.
not removing... since it now passes, additionally constructed the expected result and compared.
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, you are going to remove this test? rather, this case?
so have now added some cases to test_constructor_dtype_datetime64 similar to those in test_constructor_dtype_timedelta64 and also added the exception message check to tests/frame/test_dtypes.py
so could probably remove some of the # GH3414 related stuff
Codecov Report
@@ Coverage Diff @@
## master #24868 +/- ##
=======================================
Coverage 92.38% 92.38%
=======================================
Files 166 166
Lines 52412 52412
=======================================
Hits 48423 48423
Misses 3989 3989
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #24868 +/- ##
==========================================
- Coverage 91.25% 91.25% -0.01%
==========================================
Files 172 172
Lines 52963 52963
==========================================
- Hits 48330 48329 -1
- Misses 4633 4634 +1
Continue to review full report at Codecov.
|
@@ -688,10 +688,21 @@ def test_constructor_dtype_datetime64(self): | |||
pytest.raises(TypeError, lambda x: Series( | |||
Series(dates).astype('int') / 1000000, dtype='M8[ms]')) | |||
|
|||
msg = (r"The 'datetime64' dtype has no unit\. Please pass in" |
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.
so I DO want this test to remain, can you simply change it so it is testing with dtype='datetime64'
, IOW it raises.
Can you merge master and address latest comments? Also, it may just be me but I would find it super helpful going forward if you could use a more descriptive title here and for future PRs. We have a rather large backlog of PRs and issues so if it's not descriptive it's more work than it needs to be on the review end to keep track of what the PR is trying to address |
Closing as stale - ping if you'd like to continue |
@WillAyd : i'll need to resolve this at some point before we can activate the code checks for pytest.raises not been used as a context manager. This PR was closely related to #24827. There is no longer any activity there. So i'll include that here and change the title to relate to that issue. So if you could reopen this PR that'll be great. Thanks. |
@simonjayhawkins done! |
thanks. @WillAyd. I believe the comments have been addressed. will merge master and uncomment the current solution to #24827 which i believe @jreback was happy with, see #24812 (comment) and use np.intp to resolve the windows issue. Then see where we go from there. |
thanks @simonjayhawkins note that the test itself is pretty long (not your change), so can consider breaking it up a bit in the future. |
* master: (22 commits) Fixturize tests/frame/test_operators.py (pandas-dev#25641) Update ValueError message in corr (pandas-dev#25729) DOC: fix some grammar and inconsistency issues in the User Guide (pandas-dev#25728) ENH: Add public start, stop, and step attributes to RangeIndex (pandas-dev#25720) Make Rolling.apply documentation clearer (pandas-dev#25712) pandas-dev#25707 - Fixed flakiness in stata write test (pandas-dev#25714) Json normalize nan support (pandas-dev#25619) TST: resolve issues with test_constructor_dtype_datetime64 (pandas-dev#24868) DEPR: Deprecate box kwarg for to_timedelta and to_datetime (pandas-dev#24486) BUG: Preserve name in DatetimeIndex.snap (pandas-dev#25585) Fix concat not respecting order of OrderedDict (pandas-dev#25224) CLN: remove pandas.core.categorical (pandas-dev#25655) TST/CLN: Remove more Panel tests (pandas-dev#25675) Pinned pycodestyle (pandas-dev#25701) DOC: update date of 0.24.2 release notes (pandas-dev#25699) BUG: Fix error in replace with strings that are large numbers (pandas-dev#25616) (pandas-dev#25644) BUG: fix usage of na_sentinel with sort=True in factorize() (pandas-dev#25592) BUG: Fix to_string output when using header (pandas-dev#16718) (pandas-dev#25602) CLN: Remove unused test code (pandas-dev#25670) CLN: remove Panel from concat error message (pandas-dev#25676) ... # Conflicts: # doc/source/whatsnew/v0.25.0.rst
closes #24827
xref #24812 (comment)
while changing pytest.raises to use the context manager and check the error message it appeared that a test was not raising exceptions as originally intended.
the test was related to a legacy numpy related issue #3414