Skip to content

added validation for series datatypes #56659

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

Closed
Closed
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
5 changes: 5 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from pandas.core.dtypes.common import (
is_dict_like,
is_integer,
is_float,
is_iterator,
is_list_like,
is_object_dtype,
Expand Down Expand Up @@ -3102,6 +3103,10 @@ def diff(self, periods: int = 1) -> Series:
--------
{examples}
"""
if not lib.is_integer(periods):
if not (is_float(periods) and periods.is_integer()):
raise ValueError("periods must be an integer")
periods = int(periods)
result = algorithms.diff(self._values, periods)
return self._constructor(result, index=self.index, copy=False).__finalize__(
self, method="diff"
Expand Down