Skip to content

pd.Index().shift() claims to return None #1181

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
gogowitsch opened this issue Apr 9, 2025 · 1 comment · Fixed by #1191
Closed

pd.Index().shift() claims to return None #1181

gogowitsch opened this issue Apr 9, 2025 · 1 comment · Fixed by #1191
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff good first issue Index Related to the Index class or subclasses

Comments

@gogowitsch
Copy link

Describe the bug
The stubs claim that shift returns None, when it returns a pd.Index of the same type as the original_index

To Reproduce

from datetime import datetime

import pandas as pd

original_index = pd.date_range(
    start=datetime(2024, 2, 2),
    end=datetime(2024, 4, 2),
    freq="15min",
    inclusive="left",
    tz="Europe/Berlin",
)

new_index = original_index.shift(1)
print(original_index, new_index)
print(f"{type(original_index)}, {type(new_index)}")

I get this mypy error:

example.py:13: error: "shift" of "Index" does not return a value (it only ever returns None) [func-returns-value]

Please complete the following information:

  • macOS 15.4 (24E248)
  • Python 3.11.11
  • I am using mypy 1.11.1 and pandas-stubs 2.2.3.250308.
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Apr 9, 2025

Thanks for the report. PR with tests welcome

@Dr-Irv Dr-Irv added good first issue Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Index Related to the Index class or subclasses labels Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff good first issue Index Related to the Index class or subclasses
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants