Skip to content

STY: use pytest.raises context syntax (series) #24812

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 5 commits into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,12 @@ def test_constructor_dtype_datetime64(self):
assert s.dtype == 'M8[ns]'

# GH3414 related
msg = (r"cannot astype a datetimelike from \[datetime64\[ns\]\] to"
r" \[int32\]")
# msg = (r"cannot astype a datetimelike from \[datetime64\[ns\]\] to"
# r" \[int32\]")
# with pytest.raises(TypeError, match=msg):
Series(Series(dates).astype('int') / 1000000, dtype='M8[ms]')
# Series(Series(dates).astype('int') / 1000000, dtype='M8[ms]')
pytest.raises(TypeError, lambda x: Series(
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 raising missing 1 required positional argument: 'x' because of the lambda and not failing as intended. correcting this with the conversion to context manger is only failing on windows and again from the error message is probably not failing as intended

Copy link
Contributor

Choose a reason for hiding this comment

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

this should be raising TypeError, what happens when you use the context manager

Copy link
Member Author

Choose a reason for hiding this comment

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

it is raising TypeError in master because of the lambda. this is a bad test.

correcting it with the context manager raises TypeError: cannot astype a datetimelike from [datetime64[ns]] to [int32] but only on the windows tests (see ci failures)

i've reverted the changes to the test, but the ci is failing on an unrelated conda error at the moment.

with the changes in this PR there will still be 823 uses of pytest.raises without the cm. so i don't want to get bogged down with bad tests at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

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

k that's fine (though happy to take your change, though it should raise on windows as well). can you create an issue about this.

Series(dates).astype('int') / 1000000, dtype='M8[ms]'))

msg = (r"The 'datetime64' dtype has no unit\. Please pass in"
r" 'datetime64\[ns\]' instead\.")
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def test_astype_categorical_to_other(self):
expected = s
tm.assert_series_equal(s.astype('category'), expected)
tm.assert_series_equal(s.astype(CategoricalDtype()), expected)
msg = (r"could not convert string to float: '0 - 499'|"
msg = (r"could not convert string to float: '(0 - 499|9500 - 9999)'|"
r"invalid literal for float\(\): 9500 - 9999")
with pytest.raises(ValueError, match=msg):
s.astype('float64')
Expand Down