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

i1 = pd.date_range("2022", freq="D", periods=10)
i2 = i1.copy()  # COPY

print(i1 is i2) # False
print(id(i1), id(i2)) # 2151608624624 2151619591232
print(i1.freq) # <Day>
print(i2.freq) # <Day>

i1.freq = None

print(i1 is i2) # False
print(id(i1), id(i2)) # 2151608624624 2151619591232
print(i1.freq) # None
print(i2.freq) # None (!!)

Issue Description

See the final line. The frequency of i2 has been changed as well, even though it is a distinct object from i1.

Excuse me if this is expected.

Expected Behavior

The attributes of i2 should not change when they are changed in i1 only.

Installed Versions

INSTALLED VERSIONS ------------------ commit : 91111fd99898d9dcaa6bf6bedb662db4108da6e6 python : 3.8.13.final.0 python-bits : 64 OS : Windows OS-release : 10 Version : 10.0.19045 machine : AMD64 processor : Intel64 Family 6 Model 165 Stepping 2, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : de_DE.cp1252 pandas : 1.5.1 numpy : 1.23.4 pytz : 2022.5 dateutil : 2.8.2 setuptools : 61.2.0 pip : 21.2.2 Cython : None pytest : 7.1.1 hypothesis : None sphinx : 4.5.0 blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.2 IPython : 8.3.0 pandas_datareader: None bs4 : None bottleneck : None brotli : fastparquet : None fsspec : None gcsfs : None matplotlib : 3.6.1 numba : None numexpr : None odfpy : None openpyxl : 3.0.9 pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : None snappy : None sqlalchemy : 1.4.32 tables : None tabulate : None xarray : None xlrd : None xlwt : None zstandard : None tzdata : None

Comment From: a-reich

Just chiming in, but the method’s deep param defaults to false. If set to true this behaves as you expected.

Comment From: debnathshoham

as @a-reich rightly pointed out

1 = pd.date_range("2022", freq="D", periods=10)
i2=i1.copy(deep=True)
print(i1 is i2) # False
print(id(i1), id(i2)) # 140340502539808 140340502540240
print(i1.freq) # <Day>
print(i2.freq) # <Day>
i1.freq = None
print(i1 is i2) # False
print(id(i1), id(i2)) # 140340502539808 140340502540240
print(i1.freq) # None
print(i2.freq) # <Day>