Skip to content

Index.where(..., other) should support other with more than array-like #1419

@loicdiridollou

Description

@loicdiridollou

Describe the bug
Right now Index.where(..., other=...) only supports the strict array-like (ExtensionArray and np.array), it seems that having Series or Index works at runtime and makes sense.

To Reproduce

  1. Provide a minimal runnable pandas example that is not properly checked by the stubs.
  2. Indicate which type checker you are using (mypy or pyright).
  3. Show the error message received from that type checker while checking your example.
import pandas as pd
import numpy as np

datetime_index = pd.DatetimeIndex(pd.date_range(start="2025-01-01", freq="h", periods=48))
mask = np.ones(48, dtype=bool)

condition = datetime_index.where(mask,datetime_index - pd.Timedelta(days=1))

It yields the following error:

Argument 2 to "where" of "Index" has incompatible type "DatetimeIndex"; expected "str | bytes | date | datetime | timedelta | <13 more items> | None"  [arg-type]

Please complete the following information:

  • OS: MacOS
  • OS Version 26
  • python version 3.13
  • version of type checker 1.18.1
  • version of installed pandas-stubs main

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions