Skip to content

DOC: Index.where(..., other) other could be a Series/Index but not documented as such #62646

@loicdiridollou

Description

@loicdiridollou

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/dev/reference/api/pandas.Index.where.html#pandas.Index.where

Documentation problem

Right now the docs for where for an Index mention that the other argument can be an array-like. As opposed to Series.where and DataFrame.where where other can be a Series or DataFrame.

At runtime this works totally fine with a Series or an Index:

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))

Suggested fix for documentation

Should we allow Index/Series type for other?

Happy to make the PR, we have added this in a PR in pandas-dev/pandas-stubs#1420 so waiting for confirmation of the pandas team to move forward with it or not.
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions