Skip to content
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

Merged
merged 10 commits into from
Mar 13, 2019

Conversation

simonjayhawkins
Copy link
Member

@simonjayhawkins simonjayhawkins commented Jan 21, 2019

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

@@ -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"
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WillAyd

i'm guessing that the intended error message for this test would have been originally that raised by

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
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!

Copy link
Contributor

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.

Copy link
Contributor

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)

Copy link
Member Author

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.

Copy link
Contributor

@jreback jreback Jan 26, 2019

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?

Copy link
Member Author

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.

Copy link
Member Author

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

@WillAyd WillAyd added Testing pandas testing functions or related to the test suite Datetime Datetime data dtype labels Jan 21, 2019
@codecov
Copy link

codecov bot commented Jan 21, 2019

Codecov Report

Merging #24868 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #24868   +/-   ##
=======================================
  Coverage   92.38%   92.38%           
=======================================
  Files         166      166           
  Lines       52412    52412           
=======================================
  Hits        48423    48423           
  Misses       3989     3989
Flag Coverage Δ
#multiple 90.81% <ø> (ø) ⬆️
#single 42.89% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 12bb6d0...5418c75. Read the comment docs.

@codecov
Copy link

codecov bot commented Jan 21, 2019

Codecov Report

Merging #24868 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 89.82% <ø> (ø) ⬆️
#single 41.74% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/util/testing.py 88.98% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86879ac...13e364b. Read the comment docs.

@@ -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"
Copy link
Contributor

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.

@WillAyd
Copy link
Member

WillAyd commented Feb 12, 2019

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

@WillAyd
Copy link
Member

WillAyd commented Feb 19, 2019

Closing as stale - ping if you'd like to continue

@WillAyd WillAyd closed this Feb 19, 2019
@simonjayhawkins
Copy link
Member Author

@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 simonjayhawkins changed the title TST: follow-up to #24812 [WIP] TST: resolve issues with test_constructor_dtype_datetime64 Mar 12, 2019
@WillAyd WillAyd reopened this Mar 12, 2019
@WillAyd
Copy link
Member

WillAyd commented Mar 12, 2019

@simonjayhawkins done!

@simonjayhawkins
Copy link
Member Author

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.

@simonjayhawkins simonjayhawkins changed the title [WIP] TST: resolve issues with test_constructor_dtype_datetime64 TST: resolve issues with test_constructor_dtype_datetime64 Mar 13, 2019
@jreback jreback added this to the 0.25.0 milestone Mar 13, 2019
@jreback jreback merged commit 69ae24b into pandas-dev:master Mar 13, 2019
@jreback
Copy link
Contributor

jreback commented Mar 13, 2019

thanks @simonjayhawkins note that the test itself is pretty long (not your change), so can consider breaking it up a bit in the future.

@simonjayhawkins simonjayhawkins deleted the series-np-bug branch March 13, 2019 17:17
sighingnow added a commit to sighingnow/pandas that referenced this pull request Mar 14, 2019
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TST: test_constructors.py::TestSeriesConstructors::test_constructor_dtype_datetime64
3 participants