Skip to content

Commit

Permalink
PERF: Fixed performance regression in Series init
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Dec 30, 2019
1 parent 733eb77 commit dc9a20d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,11 @@ def construct_from_string(cls, string):
return cls(freq=string)
except ValueError:
pass
raise TypeError(f"Cannot construct a 'PeriodDtype' from '{string}'")
if isinstance(string, str):
msg = f"Cannot construct a 'PeriodDtype' from '{string}'"
else:
msg = f"'construct_from_string' expects a string, got {type(string)}"
raise TypeError(msg)

def __str__(self) -> str_type:
return self.name
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ def test_construction_from_string(self):
with pytest.raises(TypeError):
PeriodDtype.construct_from_string("datetime64[ns, US/Eastern]")

with pytest.raises(TypeError, match="list"):
PeriodDtype.construct_from_string([1, 2, 3])

def test_is_dtype(self):
assert PeriodDtype.is_dtype(self.dtype)
assert PeriodDtype.is_dtype("period[D]")
Expand Down

0 comments on commit dc9a20d

Please sign in to comment.