Skip to content

BUG: invalidate cached Index._isnan if use_inf_as_na changed? #44262

@jbrockmendel

Description

@jbrockmendel

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import numpy as np
import pandas as pd

idx = pd.Index([np.inf, np.nan], dtype=np.float64)

assert (pd.isna(idx) == idx.isna()).all()

pd.set_option("use_inf_as_na", True)

assert (pd.isna(idx) == idx.isna()).all()  # <- nope!

Issue Description

pd.isna(obj) and obj.isna() are generally interchangeable, but pd.Index caches .isna in a _isnan cache_readonly. If we want to maintain that interchangeability, we'd need to invalidate that cache.

My inclination is that it isn't worth futzing around with, but someone who uses use_inf_as_na=True might care more.

Expected Behavior

assert (pd.isna(idx) == idx.isna()).all()

Installed Versions

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions