Skip to content

BUG: pct_change with fill_method=None isn't tested nor covered by type hints #51269

Closed
@MarcoGorelli

Description

@MarcoGorelli

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

price = [np.NaN, 10, 13, np.NaN, np.NaN, 9]
df = pd. DataFrame(price, columns = ['price'])
period = 1
pct = df.price.pct_change(periods=period, fill_method=None)
print(pct)

# https://stackoverflow.com/questions/75395345/how-to-avoid-bfill-or-ffill-when-calculating-pct-change-with-nans

Issue Description

There's a code path specifically for fill_method=None:

pandas/pandas/core/generic.py

Lines 10904 to 10905 in 13db83a

if fill_method is None:
data = self

But no test hits it (check pandas-coverage.herokuapp.com/), and the type hints don't allow None

Expected Behavior

This was recently added to the docs #51262 - seeing as it does work, it should probably be tested, type hints updated, and documented?

Installed Versions

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

Labels

DocsNeeds TestsUnit test(s) needed to prevent regressionsTypingtype annotations, mypy/pyright type checkinggood first issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions