Skip to content

Commit

Permalink
BUG: DatetimeIndex.diff raising TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemanley committed Oct 30, 2023
1 parent 192a4e3 commit 0b040a1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7017,7 +7017,11 @@ def diff(self, periods: int = 1) -> Self:
Index([nan, 10.0, 10.0, 10.0, 10.0], dtype='float64')
"""
return self._constructor(self.to_series().diff(periods))
diff = self.to_series().diff(periods)
if diff.dtype != self.dtype:
# e.g. DTI.diff -> TDI
return Index(diff)
return self._constructor(diff)

@final
def round(self, decimals: int = 0) -> Self:
Expand Down

0 comments on commit 0b040a1

Please sign in to comment.