Skip to content

TST/CLN: dtype test_construct_from_string #31727

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
Changes from all commits
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
34 changes: 17 additions & 17 deletions pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,27 +233,27 @@ def test_compat(self, dtype):
def test_construction_from_string(self, dtype):
result = DatetimeTZDtype.construct_from_string("datetime64[ns, US/Eastern]")
assert is_dtype_equal(dtype, result)
msg = "Cannot construct a 'DatetimeTZDtype' from 'foo'"
with pytest.raises(TypeError, match=msg):
DatetimeTZDtype.construct_from_string("foo")

def test_construct_from_string_raises(self):
with pytest.raises(TypeError, match="notatz"):
DatetimeTZDtype.construct_from_string("datetime64[ns, notatz]")

msg = "'construct_from_string' expects a string, got <class 'list'>"
with pytest.raises(TypeError, match=re.escape(msg)):
# list instead of string
DatetimeTZDtype.construct_from_string(["datetime64[ns, notatz]"])

msg = "^Cannot construct a 'DatetimeTZDtype'"
with pytest.raises(TypeError, match=msg):
@pytest.mark.parametrize(
"string",
[
"foo",
"datetime64[ns, notatz]",
# non-nano unit
DatetimeTZDtype.construct_from_string("datetime64[ps, UTC]")
"datetime64[ps, UTC]",
# dateutil str that returns None from gettz
"datetime64[ns, dateutil/invalid]",
],
)
def test_construct_from_string_invalid_raises(self, string):
msg = f"Cannot construct a 'DatetimeTZDtype' from '{string}'"
with pytest.raises(TypeError, match=re.escape(msg)):
DatetimeTZDtype.construct_from_string(string)

def test_construct_from_string_wrong_type_raises(self):
msg = "'construct_from_string' expects a string, got <class 'list'>"
with pytest.raises(TypeError, match=msg):
# dateutil str that returns None from gettz
DatetimeTZDtype.construct_from_string("datetime64[ns, dateutil/invalid]")
DatetimeTZDtype.construct_from_string(["datetime64[ns, notatz]"])

def test_is_dtype(self, dtype):
assert not DatetimeTZDtype.is_dtype(None)
Expand Down