Skip to content
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

BUG: Less helpful SettingWithCopyWarning on new pandas version #42570

Closed
2 of 3 tasks
ntjess opened this issue Jul 16, 2021 · 2 comments · Fixed by #42633
Closed
2 of 3 tasks

BUG: Less helpful SettingWithCopyWarning on new pandas version #42570

ntjess opened this issue Jul 16, 2021 · 2 comments · Fixed by #42633
Labels
Bug Copy / view semantics Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@ntjess
Copy link

ntjess commented Jul 16, 2021

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

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

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


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

# Your code here
import numpy as np
import pandas as pd

df = pd.DataFrame(np.arange(25).reshape(5,5))

def valid_indexes(in_df: pd.DataFrame):
  return in_df.loc[:3]

valid = valid_indexes(df)
valid[2] = 3

Problem description

Before (pandas 1.2.*), the resulting warning showed my own code:

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
valid[2] = 3

Now, it only shows library code:

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  self._set_item(key, value)

This is significantly harder to diagnose.

Expected Output

The line of code I wrote to produce the error

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f00ed8f
python : 3.9.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.3.0
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.3
setuptools : 52.0.0.post20210125
Cython : None
pytest : 6.2.4
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.4.3
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.23.1
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.2
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : 1.4.15
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
numba : None

@ntjess ntjess added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 16, 2021
@ntjess ntjess changed the title BUG: Less helpful SettingsWithCopyWarning on new pandas version BUG: Less helpful SettingWithCopyWarning on new pandas version Jul 16, 2021
@MarcoGorelli MarcoGorelli added the Error Reporting Incorrect or improved errors from pandas label Jul 17, 2021
@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 20, 2021
@phofl phofl added this to the 1.3.1 milestone Jul 20, 2021
@phofl
Copy link
Member

phofl commented Jul 20, 2021

Stacklevel changed.

@simonjayhawkins
Copy link
Member

Before (pandas 1.2.*), the resulting warning showed my own code:

first bad commit: [35cc565] REF: simplify _sanitize_column (#38459) cc @jbrockmendel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Copy / view semantics Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants