-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Description
Pandas version checks
-
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 main branch of pandas.
Reproducible Example
>>> import pandas as pd
>>>
>>> index1 = pd.Index([0, 1])
>>> index2 = pd.Index([0, 1])
>>> index3 = index1.intersection(index2)
>>> index3 is index1
TrueIssue Description
The documentation for Index.intersection states:
This returns a new Index with elements common to the index and other.
However, there are cases where a reference to one of the operands is returned instead of a new instance. Subsequent operations on the returned object can end up mutating one the operands, which is unexpected.
Expected Behavior
Index.intersection should always return a new instance.
Installed Versions
pandas : 3.0.0.dev0+2728.g7bf6660984
numpy : 2.3.5
dateutil : 2.9.0.post0
pip : 25.2
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
psycopg2 : None
pymysql : None
pyarrow : None
pyiceberg : None
pyreadstat : None
pytest : None
python-calamine : None
pytz : 2025.2
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None