Skip to content

Column reappears after drop() when working on a reference of that column #13934

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

Closed
Gunthard opened this issue Aug 8, 2016 · 3 comments · Fixed by #41482
Closed

Column reappears after drop() when working on a reference of that column #13934

Gunthard opened this issue Aug 8, 2016 · 3 comments · Fixed by #41482
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@Gunthard
Copy link

Gunthard commented Aug 8, 2016

Code Sample, a copy-pastable example if possible

import pandas

df = pandas.DataFrame()
df['a'] = [1,2,3]

a = df.a

df.drop(['a'], axis=1, inplace=True)
print df.columns

a -= a.mean()
print df.columns

Current Output

Index([], dtype='object')
Index([u'a'], dtype='object')

Expected Output

Index([], dtype='object')
Index([], dtype='object')

output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Linux
OS-release: 3.19.0-65-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: de_DE.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 1.5.4
setuptools: 20.9.0
Cython: 0.23.4
numpy: 1.11.1
scipy: 0.17.1
statsmodels: 0.6.1
xarray: None
IPython: 4.0.0
sphinx: 1.3.5
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999
httplib2: 0.8
apiclient: None
sqlalchemy: 1.0.11
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.38.0
pandas_datareader: None

@Gunthard Gunthard changed the title Column reapears after drop() when working on a reference of that column Column reappears after drop() when working on a reference of that column Aug 8, 2016
@gfyoung
Copy link
Member

gfyoung commented Aug 19, 2016

Argh...memory aliasing...that's really annoying. For future reference, I would suggest not using inplace=True (it's discouraged IINM). @jreback?

@jreback
Copy link
Contributor

jreback commented Aug 19, 2016

I think the cache is not being updated _items_cache

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Difficulty Advanced labels Aug 19, 2016
@jreback jreback added this to the Next Major Release milestone Aug 19, 2016
@mroeschke
Copy link
Member

Looks to be fixed on master. Could use a test

In [19]: import pandas
    ...:
    ...: df = pandas.DataFrame()
    ...: df['a'] = [1,2,3]
    ...:
    ...: a = df.a
    ...:
    ...: df.drop(['a'], axis=1, inplace=True)

In [20]: df.columns
Out[20]: Index([], dtype='object')

In [21]: a -= a.mean()

In [22]: df.columns
Out[22]: Index([], dtype='object')

In [23]: pd.__version__
Out[23]: '1.3.0.dev0+1485.g6abb567cb1'

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Bug Indexing Related to indexing on series/frames, not to indexes themselves labels May 1, 2021
@mroeschke mroeschke modified the milestones: Contributions Welcome, 1.3 May 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants