-
-
Couldn't load subscription status.
- Fork 150
Description
Describe the bug
The pandas-stubs type annotations for DataFrame.pct_change() method do not include the axis parameter, even though the actual pandas implementation accepts it via **kwargs. According to the pandas documentation, pct_change() accepts additional keyword arguments that are passed to DataFrame.shift or Series.shift, and since shift() accepts an axis parameter, pct_change() should also accept it.
To Reproduce
- Minimal pandas example that should work but fails type checking:
import pandas as pd
# Create sample data
df = pd.DataFrame({
'A': [100, 110, 120],
'B': [200, 180, 160]
})
# This works at runtime but fails type checking
result = df[['A', 'B']].pct_change(axis=1)
print(result)-
Type checker:
mypy -
Error message:
error: Unexpected keyword argument "axis" for "pct_change" of "DataFrame" [call-arg]
Please complete the following information:
OS: Linux
OS Version: 6.8.0-45-generic
python version: 3.12
version of type checker: mypy 1.18.2
version of installed pandas-stubs: 2.3.2.250926
Additional context
- The pandas documentation at https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.pct_change.html clearly states that
pct_change()accepts**kwargswhich are passed toDataFrame.shiftorSeries.shift - The
shift()method accepts anaxisparameter, sopct_change()should also accept it through**kwargs - This is a common pattern in pandas where methods accept additional parameters via
**kwargsfor flexibility - The current pandas-stubs signature only includes:
periods,fill_method,freq, andfill_valueparameters, but is missing theaxisparameter that should be available via**kwargs