Skip to content

Commit

Permalink
API: Raise more specific exception on concat([None])
Browse files Browse the repository at this point in the history
  • Loading branch information
thatneat authored and jreback committed Oct 10, 2014
1 parent 32c5016 commit ce79c80
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion doc/source/v0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ API changes
- add ``copy=True`` argument to ``pd.concat`` to enable pass thru of complete blocks (:issue:`8252`)

- Added support for numpy 1.8+ data types (``bool_``, ``int_``, ``float_``, ``string_``) for conversion to R dataframe (:issue:`8400`)

- Concatenating no objects will now raise a ``ValueError`` rather than a bare ``Exception``.
- Concatenation errors will now be sub-classes of ``ValueError`` rather than raw ``Exception`` (:issue:`8501`)

This comment has been minimized.

Copy link
@jason-curtis

jason-curtis Oct 13, 2014

Contributor

@jreback this should say 'merge errors' (MergeError), not 'concatenation errors', shouldn't it? been away for the weekend, sorry for the slow response.

This comment has been minimized.

Copy link
@jreback

jreback Oct 13, 2014

Contributor

fixed 69e0f91 thansk!

- ``DataFrame.plot`` and ``Series.plot`` keywords are now have consistent orders (:issue:`8037`)

.. _whatsnew_0150.memory:
Expand Down
6 changes: 3 additions & 3 deletions pandas/tools/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def merge(left, right, how='inner', on=None, left_on=None, right_on=None,
merge.__doc__ = _merge_doc % '\nleft : DataFrame'


class MergeError(Exception):
class MergeError(ValueError):
pass


Expand Down Expand Up @@ -679,7 +679,7 @@ def concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False,
If a dict is passed, the sorted keys will be used as the `keys`
argument, unless it is passed, in which case the values will be
selected (see below). Any None objects will be dropped silently unless
they are all None in which case an Exception will be raised
they are all None in which case a ValueError will be raised
axis : {0, 1, ...}, default 0
The axis to concatenate along
join : {'inner', 'outer'}, default 'outer'
Expand Down Expand Up @@ -764,7 +764,7 @@ def __init__(self, objs, axis=0, join='outer', join_axes=None,
keys = clean_keys

if len(objs) == 0:
raise Exception('All objects passed were None')
raise ValueError('All objects passed were None')

# consolidate data & figure out what our result ndim is going to be
ndims = set()
Expand Down
16 changes: 8 additions & 8 deletions pandas/tools/tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ def test_join_on(self):
self.assertTrue(np.isnan(joined['three']['c']))

# merge column not p resent
self.assertRaises(Exception, target.join, source, on='E')
self.assertRaises(KeyError, target.join, source, on='E')

# overlap
source_copy = source.copy()
source_copy['A'] = 0
self.assertRaises(Exception, target.join, source_copy, on='A')
self.assertRaises(ValueError, target.join, source_copy, on='A')

def test_join_on_fails_with_different_right_index(self):
with tm.assertRaises(ValueError):
Expand Down Expand Up @@ -551,15 +551,15 @@ def test_merge_index_singlekey_inner(self):
assert_frame_equal(result, expected.ix[:, result.columns])

def test_merge_misspecified(self):
self.assertRaises(Exception, merge, self.left, self.right,
self.assertRaises(ValueError, merge, self.left, self.right,
left_index=True)
self.assertRaises(Exception, merge, self.left, self.right,
self.assertRaises(ValueError, merge, self.left, self.right,
right_index=True)

self.assertRaises(Exception, merge, self.left, self.left,
self.assertRaises(ValueError, merge, self.left, self.left,
left_on='key', on='key')

self.assertRaises(Exception, merge, self.df, self.df2,
self.assertRaises(ValueError, merge, self.df, self.df2,
left_on=['key1'], right_on=['key1', 'key2'])

def test_merge_overlap(self):
Expand Down Expand Up @@ -854,7 +854,7 @@ def test_overlapping_columns_error_message(self):
df.columns = ['key', 'foo', 'foo']
df2.columns = ['key', 'bar', 'bar']

self.assertRaises(Exception, merge, df, df2)
self.assertRaises(ValueError, merge, df, df2)

def _check_merge(x, y):
for how in ['inner', 'left', 'outer']:
Expand Down Expand Up @@ -2122,7 +2122,7 @@ def test_concat_exclude_none(self):
pieces = [df[:5], None, None, df[5:]]
result = concat(pieces)
tm.assert_frame_equal(result, df)
self.assertRaises(Exception, concat, [None, None])
self.assertRaises(ValueError, concat, [None, None])

def test_concat_datetime64_block(self):
from pandas.tseries.index import date_range
Expand Down

0 comments on commit ce79c80

Please sign in to comment.