Skip to content

BUG: Index.where vs Series.where mismatch #37682

@jbrockmendel

Description

@jbrockmendel

If in merge._maybe_add_join_keys we replace a call to Index.where with a call to Series.where, we get a test failure because of the following mismatch:

dr = pd.date_range("2001-01-01", periods=3)
lvals = pd.DatetimeIndex([dr[0], dr[1], pd.NaT])._data
rvals = pd.Categorical([dr[0], pd.NaT, dr[2]])

mask = np.array([False, False, True])

>>> pd.Series(lvals).where(~mask, rvals)._values
array([Timestamp('2001-01-01 00:00:00'), Timestamp('2001-01-02 00:00:00'),
       978480000000000000], dtype=object)

>>> pd.Index(lvals).where(~mask, rvals)._values
<DatetimeArray>
['2001-01-01 00:00:00', '2001-01-02 00:00:00', '2001-01-03 00:00:00']
Length: 3, dtype: datetime64[ns]

The Index version looks better behaved. These should share an implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSeriesSeries data structure

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions