Skip to content

Commit a2a35a8

Browse files
TST/CLN: dtype test_construct_from_string (#31727)
1 parent 120f35f commit a2a35a8

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

pandas/tests/dtypes/test_dtypes.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -233,27 +233,27 @@ def test_compat(self, dtype):
233233
def test_construction_from_string(self, dtype):
234234
result = DatetimeTZDtype.construct_from_string("datetime64[ns, US/Eastern]")
235235
assert is_dtype_equal(dtype, result)
236-
msg = "Cannot construct a 'DatetimeTZDtype' from 'foo'"
237-
with pytest.raises(TypeError, match=msg):
238-
DatetimeTZDtype.construct_from_string("foo")
239-
240-
def test_construct_from_string_raises(self):
241-
with pytest.raises(TypeError, match="notatz"):
242-
DatetimeTZDtype.construct_from_string("datetime64[ns, notatz]")
243-
244-
msg = "'construct_from_string' expects a string, got <class 'list'>"
245-
with pytest.raises(TypeError, match=re.escape(msg)):
246-
# list instead of string
247-
DatetimeTZDtype.construct_from_string(["datetime64[ns, notatz]"])
248236

249-
msg = "^Cannot construct a 'DatetimeTZDtype'"
250-
with pytest.raises(TypeError, match=msg):
237+
@pytest.mark.parametrize(
238+
"string",
239+
[
240+
"foo",
241+
"datetime64[ns, notatz]",
251242
# non-nano unit
252-
DatetimeTZDtype.construct_from_string("datetime64[ps, UTC]")
243+
"datetime64[ps, UTC]",
244+
# dateutil str that returns None from gettz
245+
"datetime64[ns, dateutil/invalid]",
246+
],
247+
)
248+
def test_construct_from_string_invalid_raises(self, string):
249+
msg = f"Cannot construct a 'DatetimeTZDtype' from '{string}'"
250+
with pytest.raises(TypeError, match=re.escape(msg)):
251+
DatetimeTZDtype.construct_from_string(string)
253252

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

258258
def test_is_dtype(self, dtype):
259259
assert not DatetimeTZDtype.is_dtype(None)

0 commit comments

Comments
 (0)