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: passing a non-dict mapping to pd.concat raises a TypeError #32863

Closed
pbourguignon opened this issue Mar 20, 2020 · 0 comments · Fixed by #32953
Closed

BUG: passing a non-dict mapping to pd.concat raises a TypeError #32863

pbourguignon opened this issue Mar 20, 2020 · 0 comments · Fixed by #32953
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@pbourguignon
Copy link
Contributor

Code Sample, a copy-pastable example if possible

class MyMapping(Mapping):
    def __init__(self, content=None):
        if content:
            self._content = content
        else:
            self._content = {}
    def __getitem__(self, key):
        return self._content[key]
    def __iter__(self):
        return iter(self._content)
    def __len__(self):
        return len(self._content)   

objs = MyMapping({"a": pd.DataFrame({"_0": [0.], "_1": [0.]}), "b": pd.DataFrame({"_0": [0.], "_1": [0.]})}
concat_objs = pd.concat(objs, axis=1)

Problem description

The above code raises a TypeError with the message "cannot concatenate object of type '<class 'str'>'; only Series and DataFrame objs are valid".

As the documentation explicitly specifies that the argument objs can be a mapping of Series or DataFrame objects, the expected behaviour is to just proceed.

Expected Output

The concatenated data frame.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.7.final.0
python-bits : 64
OS : Darwin
OS-release : 19.3.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_GB.UTF-8
pandas : 0.25.3
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 19.3.1
setuptools : 41.0.0
Cython : None
pytest : 5.3.2
hypothesis : None
sphinx : 1.8.5
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.3.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : 7.12.0
pandas_datareader: None
bs4 : None
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.3.1
matplotlib : 3.1.3
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : 3.6.1
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None

@simonjayhawkins simonjayhawkins added Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Mar 20, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1 milestone Mar 23, 2020
@simonjayhawkins simonjayhawkins changed the title Inconsistent type hint in pd.concat BUG: passing a non-dict mapping to pd.concat raises a TypeError Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
2 participants