You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't think that adding a new column to a DataFrame should change index in any way, let alone change its type and remove its name. It doesn't matter if there's no actual data - it still forces the user to write special checks.
The text was updated successfully, but these errors were encountered:
p-himik
changed the title
Calling assign on an empty DataFrame changes index type, removes index name
Adding a column via assign or __setattr__ on an empty DataFrame changes index type, removes index name
Jan 22, 2019
The bug in is in DataFrame.__setitem__, not assign.
In [23]: df=pd.DataFrame({'a': []}, index=pd.Index([], name='my_index'))
In [24]: df['b'] = []
In [25]: df.indexOut[25]: RangeIndex(start=0, stop=0, step=1)
Can you check if we have an issue for this? It sounds familiar.
p-himik
changed the title
Adding a column via assign or __setattr__ on an empty DataFrame changes index type, removes index name
Adding a column via assign or __setitem__ on an empty DataFrame changes index type, removes index name
Jan 22, 2019
Code Sample, a copy-pastable example if possible
Problem description
I don't think that adding a new column to a DataFrame should change index in any way, let alone change its type and remove its name. It doesn't matter if there's no actual data - it still forces the user to write special checks.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.7.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.18.0-13-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.23.4
pytest: None
pip: 18.1
setuptools: 40.6.3
Cython: None
numpy: 1.15.4
scipy: None
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: None
patsy: None
dateutil: 2.7.5
pytz: 2018.9
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: