-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
add match to bare pyteset.raises() - arrays #33010
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
Conversation
@sathyz Can you please change the word "closes" to the word "ref"? |
@@ -57,7 +57,7 @@ def test_overlaps_interval_container(self, constructor, other_constructor): | |||
# TODO: modify this test when implemented | |||
interval_container = constructor.from_breaks(range(5)) | |||
other_container = other_constructor.from_breaks(range(5)) | |||
with pytest.raises(NotImplementedError): | |||
with pytest.raises(NotImplementedError, match=None): |
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.
with pytest.raises(NotImplementedError, match=None): | |
with pytest.raises(NotImplementedError, match="^$"): |
msg = ( | ||
r"'value' should be a 'Timestamp', 'NaT', or array of those. " | ||
r"Got 'timedelta64' instead.|" | ||
r"'value' should be a 'Timedelta', 'NaT', or array of those. " | ||
r"Got 'datetime64' instead.|" | ||
r"'value' should be a 'Timedelta', 'NaT', or array of those. " | ||
r"Got 'int' instead.|" | ||
r"'value' should be a 'Timestamp', 'NaT', or array of those. " | ||
r"Got 'int' instead.|" | ||
r"'value' should be a 'Period', 'NaT', or array of those. " | ||
r"Got 'datetime64' instead.|" | ||
r"'value' should be a 'Period', 'NaT', or array of those. " | ||
r"Got 'timedelta64' instead.|" | ||
r"'value' should be a 'Period', 'NaT', or array of those. " | ||
r"Got 'int' instead." | ||
) |
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.
We are trying to use the pattern of:
msg = "|".join(
[
"foo",
"bar,
"baz"
]
)
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.
After having a second look, I think we can have this as a single string
msg = ( | |
r"'value' should be a 'Timestamp', 'NaT', or array of those. " | |
r"Got 'timedelta64' instead.|" | |
r"'value' should be a 'Timedelta', 'NaT', or array of those. " | |
r"Got 'datetime64' instead.|" | |
r"'value' should be a 'Timedelta', 'NaT', or array of those. " | |
r"Got 'int' instead.|" | |
r"'value' should be a 'Timestamp', 'NaT', or array of those. " | |
r"Got 'int' instead.|" | |
r"'value' should be a 'Period', 'NaT', or array of those. " | |
r"Got 'datetime64' instead.|" | |
r"'value' should be a 'Period', 'NaT', or array of those. " | |
r"Got 'timedelta64' instead.|" | |
r"'value' should be a 'Period', 'NaT', or array of those. " | |
r"Got 'int' instead." | |
) | |
msg = ( | |
"'value' should be a '(Timestamp|Timedelta|Period)', 'NaT', or array of those. " | |
"Got '(timedelta64|datetime64|int)' instead." | |
) |
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.
assertions fail when I use this,
E AssertionError: Pattern "'value' should be a '(Timestamp|Timedelta|Period)','NaT', or array of those. Got '(timedelta64|datetime64|int)' instead." not found in "'value' should be a 'Timedelta', 'NaT', or array of those. Got 'datetime64' instead."
I'm trying to investigate as follows,
>>> import re
>>> msg = "'value' should be a 'Timedelta', 'NaT', or array of those. Got 'datetime64' instead."
>>> pat = r"'value' should be a '(Timestamp|Timedelta|Period)', 'NaT', or array of those. Got '(timedelta64|datetimee64|int)' instead."
>>> re.search(pat, msg)
>>>
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.
it looks like missing a space after comma
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.
Ah my bad.
@@ -108,14 +108,20 @@ def test_take_fill(self): | |||
result = arr.take([-1, 1], allow_fill=True, fill_value=pd.NaT) | |||
assert result[0] is pd.NaT | |||
|
|||
with pytest.raises(ValueError): | |||
arr.take([0, 1], allow_fill=True, fill_value=2) | |||
value = 2 |
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.
can you split this out from test_take_fill as a separate test, say test_take_fill_raises and parametrize over value.
thanks @sathyz |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff