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

SettingWithCopyWarning single- vs mixed-type dataframes #24315

Closed
ayorgo opened this issue Dec 17, 2018 · 3 comments
Closed

SettingWithCopyWarning single- vs mixed-type dataframes #24315

ayorgo opened this issue Dec 17, 2018 · 3 comments

Comments

@ayorgo
Copy link

ayorgo commented Dec 17, 2018

Problem description

It seems that pandas (at least v0.23.4) handles mixed-type and single-type dataframes differently when it comes to throwing SettingWithCopyWarning

    df = pd.DataFrame({'a': [4, 5, 6], 'c': [3, 2, 1]})
    df._is_view # False
    df._is_cached # False
    df._is_mixed_type # False

    df.iloc[-1]['c'] = 42 # no warning
    df = pd.DataFrame({'a': ['x', 'y', 'z'], 'c': ['t', 'u', 'v']})
    df._is_view # False
    df._is_cached # False
    df._is_mixed_type # False

    df.iloc[-1]['c'] = 'f' # no warning
    df = pd.DataFrame({'a': ['x', 'y', 'z'], 'c': [3, 2, 1]})
    df._is_view # False
    df._is_cached # False
    df._is_mixed_type # True

    df.iloc[-1]['c'] = 42 # SettingWithCopyWarning: ...

Expected Output

SettingWithCopyWarning should appear in all three cases above.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-38-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8

pandas: 0.23.4
pytest: 3.2.1
pip: 18.0
setuptools: 40.2.0
Cython: 0.26.1
numpy: 1.13.3
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.7.3
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 3.0.1
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.0
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.1.13
pymysql: None
psycopg2: 2.7.4 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented Dec 17, 2018

a non mixed type frame is a pure view and is not subject to this warning when set with a compatible value

this is by definition: please read the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html?highlight=settingwithcopy#returning-a-view-versus-a-copy

@jreback jreback closed this as completed Dec 17, 2018
@ayorgo
Copy link
Author

ayorgo commented Dec 17, 2018

Thanks for the prompt and definitive reply @jreback.

However, I'm struggling to find the line in the docs that says "a non-mixed type frame is a pure view".
Could you please point out the exact line in the docs that says that?

Thank you.

@jreback
Copy link
Contributor

jreback commented Dec 17, 2018

what exactly is the issue? the warning happens when it’s relevant. the docs point out when it happens. they don’t point out when it doesn’t which is most of the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants