-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
Series .attrs is not correctly maintained/propagated in to_frame #31452
Comments
#28394 is exploring this a bit (stalled for now though). Specifically https://github.com/pandas-dev/pandas/pull/28394/files#diff-03b380f521c43cf003207b0711bac67fR5275 Basically we need to call In other cases, like Finally, we need to consider the performance overhead of calling Concretely, I think we can keep calling |
As a default strategy for methods with multiple NDFrames, like As an alternative, perhaps one could replicate the |
Closing this as a duplicate of #28283 |
Hi, it seems that the
.attrs
dict (for storing metadata) is not always propagated correctly. E.g.Code Sample
Problem description
As @jorisvandenbossche commented here, it seems that this is because there are a few places in pandas where calls to
finalize
are missing.I ran into it mainly in the "expanddim" direction (from Series to DF). Copying, subsetting and manipulating a Dataframe column that has
attrs
explicitly set, in contrast, seems to work without losing the metadata. I haven't tried more complicated cases, like aggregations (I don't know much about pandas internals, but from previous attempts to implement metadata in my own subclass I seem to remember that these have special code paths in the BlockManager parts, where I suspect the same or related problem may occur...).Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.8.0.final.0
python-bits : 64
OS : Darwin
OS-release : 19.2.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 1.0.0
numpy : 1.17.3
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.1.0.post20200119
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.11.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: