Pandas version checks
-
[x] I have checked that this issue has not already been reported.
-
[x] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
pd.options.mode.copy_on_write = True
idx = pd.Index(['a', 'b', 'c'], dtype="string[pyarrow]")
pd.Series(idx).replace({"z": "b", "a": "d"})
Issue Description
The above code raises the following issue:
NotImplementedError: eq not implemented for <class 'pandas.core.internals.blocks.ExtensionBlock'>
Expected Behavior
The code should run without raising any error as it does without the CoW clause, shouldn't it?
Installed Versions
Comment From: jbrockmendel
cc @phofl
Comment From: rhshadrach
I haven't run a bisection, but this looks likely to be due to https://github.com/pandas-dev/pandas/pull/52008. Having the weakref to an Index looks like it could be a footgun due to equality comparisons, but we can at least work around here by replacing
https://github.com/pandas-dev/pandas/blob/e72c8a1e0ad421c1b8a7b918d995f24bed595cc3/pandas/core/internals/blocks.py#L871-L873
with something like
idx = next(iter(k for k, e in enumerate(b.refs.referenced_blocks) if e() is b))
b.refs.referenced_blocks.pop(idx)
Not familiar with how refs to index objects are handled elsewhere.