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 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 master branch of pandas.
Reproducible Example
# I add attributes to a DataFramedf=pd.DataFrame(dict(column1=[1,2,3,4], column2=[1,2,3,4]))
df.attrs['name'] ="hello"print(df)
print(df.attrs)
OUT:
column1column2011122233344
{'name': 'hello'}
# When I change the dtype, the attribute is still there (as expected)df1=df.astype(float)
print(df1)
print(df1.attrs)
OUT:
column1column201.01.012.02.023.03.034.04.0
{'name': 'hello'}
# But when I specify the dtype for specific columns, the attributes are lostdf2=df.astype({'column1':float})
print(df2)
print(df2.attrs)
OUT:
column1column201.0112.0223.0334.04
{}
Issue Description
I assigned attributes to a DataFrame. When I change the DataFrame dtype with df.astype(float), the DataFrame attribute are retained, as expected. But when I change the dtype for specific columns with df.astype({'column1':float}), the attributes are lost.
Expected Behavior
I expected the DataFrame to retrain the attributes after specifying the dtype for specific columns as it does when I specify the dtype for the full DataFrame.
Installed Versions
INSTALLED VERSIONS
commit : 945c9ed
python : 3.9.7.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.18-24.78-default
Version : #1 SMP Mon Aug 2 21:00:23 UTC 2021 (a13100d)
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
I have a quick question about how I am planning to fix this bug. I am thinking of adding a finalize call to propogate the metadata right after line 5877 in generic.py:
[5877] result.columns = self.columns
Can anyone think of any issues this may bring up with performance? I know finalize is noted as sometimes taking up a bit of time compared to others, but I believe it is necessary to fix this issue.
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 master branch of pandas.
Reproducible Example
Issue Description
I assigned attributes to a DataFrame. When I change the DataFrame dtype with
df.astype(float)
, the DataFrame attribute are retained, as expected. But when I change the dtype for specific columns withdf.astype({'column1':float})
, the attributes are lost.Expected Behavior
I expected the DataFrame to retrain the attributes after specifying the dtype for specific columns as it does when I specify the dtype for the full DataFrame.
Installed Versions
INSTALLED VERSIONS
commit : 945c9ed
python : 3.9.7.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.18-24.78-default
Version : #1 SMP Mon Aug 2 21:00:23 UTC 2021 (a13100d)
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.3.4
numpy : 1.21.3
pytz : 2021.3
dateutil : 2.8.2
pip : 21.3.1
setuptools : 58.2.0
Cython : None
pytest : 6.2.5
hypothesis : None
sphinx : 4.0.3
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.0
IPython : 7.28.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
fsspec : 2021.10.1
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : 2021.10.1
scipy : 1.7.1
sqlalchemy : 1.4.26
tables : None
tabulate : None
xarray : 0.19.0
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: