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

BUG: yaml.dump throws AttributeError on dataframe – problem with reduce? #42804

Closed
2 of 3 tasks
allefeld opened this issue Jul 29, 2021 · 3 comments
Closed
2 of 3 tasks
Labels
Duplicate Report Duplicate issue or pull request

Comments

@allefeld
Copy link

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandas.
  • (optional) I have confirmed this bug exists on the master branch of pandas.

Please note

I have reported this problem for PyYAML as yaml/pyyaml#541, but one of the maintainers says that this cannot be fixed on their side, but is caused by the way Pandas implements reduce.

Code Sample, a copy-pastable example

Code:

import pandas as pd
import numpy as np
import yaml

x = pd.DataFrame({
    'a': np.array([1.0, 2.0])
})

yaml.dump(x)

Result:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/__init__.py", line 290, in dump
    return dump_all([data], stream, Dumper=Dumper, **kwds)
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/__init__.py", line 278, in dump_all
    dumper.represent(data)
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/representer.py", line 27, in represent
    node = self.represent_data(data)
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/representer.py", line 342, in represent_object
    return self.represent_mapping(
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/representer.py", line 118, in represent_mapping
    node_value = self.represent_data(item_value)
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/representer.py", line 346, in represent_object
    return self.represent_sequence(tag+function_name, args)
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/representer.py", line 92, in represent_sequence
    node_item = self.represent_data(item)
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/representer.py", line 48, in represent_data
    node = self.yaml_representers[data_types[0]](self, data)
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/representer.py", line 286, in represent_tuple
    return self.represent_sequence('tag:yaml.org,2002:python/tuple', data)
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/representer.py", line 92, in represent_sequence
    node_item = self.represent_data(item)
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/representer.py", line 52, in represent_data
    node = self.yaml_multi_representers[data_type](self, data)
  File "/home/ca/.conda/envs/std/lib/python3.8/site-packages/yaml/representer.py", line 331, in represent_object
    if function.__name__ == '__newobj__':
AttributeError: 'functools.partial' object has no attribute '__name__'

Python 3.8.10 | packaged by conda-forge | (default, May 11 2021, 07:01:05)
PyYAML 5.4.1
Pandas 1.3.1
NumPy 1.21.1

Problem description

This prevents dataframes from being saved as YAML.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : c7f7443
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.0-17-amd64
Version : #1 SMP Debian 4.19.194-3 (2021-07-18)
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.1
numpy : 1.21.1
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.1
setuptools : 49.6.0.post20210108
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.25.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.07.0
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : 5.0.0
pyxlsb : None
s3fs : None
scipy : 1.7.0
sqlalchemy : None
tables : None
tabulate : None
xarray : 0.19.0
xlrd : None
xlwt : None
numba : 0.53.1

@allefeld allefeld added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 29, 2021
@allefeld
Copy link
Author

allefeld commented Jul 29, 2021

If this can't or won't be fixed, I'd be grateful for a tip reverting to which version of Pandas might be a workaround (last major changes to reduce).

Reverting to 1.2.5 is a workaround.

@jbrockmendel
Copy link
Member

xref #42748

@phofl
Copy link
Member

phofl commented Jul 29, 2021

Closing as duplicate

@phofl phofl closed this as completed Jul 29, 2021
@phofl phofl added Duplicate Report Duplicate issue or pull request and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants