Skip to content

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

Closed
@gogowitsch

Description

@gogowitsch

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffIndexRelated to the Index class or subclassesgood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions