Skip to content

pandas-stubs: Missing axis parameter in DataFrame.pct_change() type annotations #1441

@leodrivera

Description

@leodrivera

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

  1. 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)
  1. Type checker: mypy

  2. 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 **kwargs which are passed to DataFrame.shift or Series.shift
  • The shift() method accepts an axis parameter, so pct_change() should also accept it through **kwargs
  • This is a common pattern in pandas where methods accept additional parameters via **kwargs for flexibility
  • The current pandas-stubs signature only includes: periods, fill_method, freq, and fill_value parameters, but is missing the axis parameter that should be available via **kwargs

Metadata

Metadata

Assignees

No one assigned

    Labels

    API - ConsistencyInternal Consistency of API/BehaviorDataFrameDataFrame data structure

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions