-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame.select_dtypes returns reference to original DataFrame #48090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@jorisvandenbossche thanks for looking into this issue and fixing it! FWIW, PR reviewed and approved 👍 |
I noticed this broke our code in 1.5 since we are depending on the https://pandas.pydata.org/pandas-docs/stable/whatsnew/v1.5.0.html#backwards-incompatible-api-changes Can we also put there? |
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
Issue Description
On Pandas 1.3.4 and previously, mutating the
DataFrame
returned byselect_dtypes
didn't change the originalDataFrame
. However, on 1.4.3, it appears mutating the selectedDataFrame
changes the original one. I suspect this is the PR that has caused the change in behavior: #42611On 1.4.3, the original
DataFrame
is mutated:Expected Behavior
on 1.3.4, the original
DataFrame
is unchanged:Installed Versions
pandas : 1.4.3
numpy : 1.23.2
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 63.2.0
pip : 22.2.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : 2.1.1
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : 0.8.10
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: