isi-vista / immutablecollections

A library for immutable collections, in the spirit of Guava's Immutable Collections.
MIT License
3 stars 1 forks source link

Pandas `concat` cannot take an ImmutableDict #71

Open berquist opened 4 years ago

berquist commented 4 years ago
>>> pd.concat(scores_per_document)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/berquist/.anaconda/envs/event-extraction-3.6/lib/python3.6/site-packages/pandas/core/reshape/concat.py", line 255, in concat
    sort=sort,
  File "/Users/berquist/.anaconda/envs/event-extraction-3.6/lib/python3.6/site-packages/pandas/core/reshape/concat.py", line 332, in __init__
    raise TypeError(msg)
TypeError: cannot concatenate object of type '<class 'str'>'; only Series and DataFrame objs are valid
>>> type(scores_per_document)
immutablecollections._immutabledict.RegularDictBackedImmutableDict
>>> type(dict(scores_per_document))
<class 'dict'>
>>> pd.concat(dict(scores_per_document))
                                                              tp   fp   fn  precision  recall     f1
AFP_ENG_20030323.0020              Personnel.Start-Position  0.0  0.0  0.0        0.0     0.0    0.0
                                   Personnel.End-Position    0.0  0.0  0.0        0.0     0.0    0.0
                                   Personnel.Nominate        0.0  0.0  0.0        0.0     0.0    0.0
                                   Personnel.Elect           0.0  0.0  0.0        0.0     0.0    0.0
                                   Movement.Transport        3.0  0.0  0.0      100.0   100.0  100.0
...                                                          ...  ...  ...        ...     ...    ...
AGGRESSIVEVOICEDAILY_20050124.1354 Justice.Execute           0.0  0.0  0.0        0.0     0.0    0.0
                                   Justice.Extradite         0.0  0.0  0.0        0.0     0.0    0.0
                                   Justice.Appeal            0.0  0.0  0.0        0.0     0.0    0.0
                                   Justice.Pardon            0.0  0.0  0.0        0.0     0.0    0.0
                                   __ALL_EVENTS_COMBINED__   2.0  0.0  0.0      100.0   100.0  100.0

[660 rows x 6 columns]
gabbard commented 4 years ago

@berquist : I don't think this is something we can do anything about. The problem is here: https://github.com/pandas-dev/pandas/blob/83812e1ba93b7857b8222e6651c823a88223472f/pandas/core/reshape/concat.py#L293 . You could file an issue+PR with pandas requesting it become isinstance(objs, Mapping).

gabbard commented 4 years ago

There is a Pandas issue corresponding to this: https://github.com/pandas-dev/pandas/issues/6792