Skip to content

ERR: better concat error messages #9157 #9172

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,7 @@ Other API Changes
^^^^^^^^^^^^^^^^^

- Line and kde plot with ``subplots=True`` now uses default colors, not all black. Specify ``color='k'`` to draw all lines in black (:issue:`9894`)
- Calling the ``.value_counts`` method on a Series with ``categorical`` dtype now returns a
Series with a ``CategoricalIndex`` (:issue:`10704`)
- Calling the ``.value_counts`` method on a Series with ``categorical`` dtype now returns a Series with a ``CategoricalIndex`` (:issue:`10704`)
- Enable writing Excel files in :ref:`memory <_io.excel_writing_buffer>` using StringIO/BytesIO (:issue:`7074`)
- Enable serialization of lists and dicts to strings in ExcelWriter (:issue:`8188`)
- Allow passing `kwargs` to the interpolation methods (:issue:`10378`).
Expand Down Expand Up @@ -526,6 +525,7 @@ Series with a ``CategoricalIndex`` (:issue:`10704`)
``return np.datetime64('NaT')`` ``to_datetime64`` (unchanged)
``raise ValueError`` All other public methods (names not beginning with underscores)
=============================== ===============================================================
- Improved error message when concatenating an empty iterable of dataframes (:issue:`9157`)

.. _whatsnew_0170.deprecations:

Expand Down
10 changes: 6 additions & 4 deletions pandas/tools/merge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
SQL-style merge routines
"""
import types

import numpy as np
from pandas.compat import range, long, lrange, lzip, zip, map, filter
Expand All @@ -17,11 +16,9 @@
concatenate_block_managers)
from pandas.util.decorators import Appender, Substitution
from pandas.core.common import ABCSeries
from pandas.io.parsers import TextFileReader

import pandas.core.common as com

import pandas.lib as lib
import pandas.algos as algos
import pandas.hashtable as _hash

Expand Down Expand Up @@ -775,9 +772,14 @@ def __init__(self, objs, axis=0, join='outer', join_axes=None,
if keys is None:
keys = sorted(objs)
objs = [objs[k] for k in keys]
else:
objs = list(objs)

if len(objs) == 0:
raise ValueError('No objects to concatenate')

if keys is None:
objs = [obj for obj in objs if obj is not None ]
objs = [obj for obj in objs if obj is not None]
else:
# #1649
clean_keys = []
Expand Down
17 changes: 17 additions & 0 deletions pandas/tools/tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2552,6 +2552,23 @@ def _constructor(self):

tm.assertIsInstance(result, NotADataFrame)

def test_empty_sequence_concat(self):
# GH 9157
empty_pat = "[Nn]o objects"
none_pat = "objects.*None"
test_cases = [
((), empty_pat),
([], empty_pat),
({}, empty_pat),
([None], none_pat),
([None, None], none_pat)
]
for df_seq, pattern in test_cases:
assertRaisesRegexp(ValueError, pattern, pd.concat, df_seq)

pd.concat([pd.DataFrame()])
pd.concat([None, pd.DataFrame()])
pd.concat([pd.DataFrame(), None])

if __name__ == '__main__':
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
Expand Down