Skip to content

BUG : Series.to_timestamp and Series.to_period raise user-facing AssertionError #34067

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 10 commits into from
May 20, 2020
6 changes: 4 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4661,7 +4661,8 @@ def to_timestamp(self, freq=None, how="start", copy=True) -> "Series":
if copy:
new_values = new_values.copy()

assert isinstance(self.index, (ABCDatetimeIndex, ABCPeriodIndex))
if not isinstance(self.index, (ABCDatetimeIndex, ABCPeriodIndex)):
raise TypeError(f"unsupported Type {self.index}")
new_index = self.index.to_timestamp(freq=freq, how=how)
return self._constructor(new_values, index=new_index).__finalize__(
self, method="to_timestamp"
Expand All @@ -4688,7 +4689,8 @@ def to_period(self, freq=None, copy=True) -> "Series":
if copy:
new_values = new_values.copy()

assert isinstance(self.index, ABCDatetimeIndex)
if not isinstance(self.index, ABCDatetimeIndex):
raise TypeError(f"unsupported Type {self.index}")
new_index = self.index.to_period(freq=freq)
return self._constructor(new_values, index=new_index).__finalize__(
self, method="to_period"
Expand Down