diff --git a/CHANGES b/CHANGES index 8d30f716..2ada18e1 100644 --- a/CHANGES +++ b/CHANGES @@ -25,6 +25,8 @@ Enhancements Deprecations Fixes + - `alchemlyb.concat()` should raise ValueError when given empty list, to be compatible with + pandas.concat() (issue #150, PR #152). - Fix the support for pandas >= 1.3 (issue #147, PR #148). - Fix separate_dhdl not work for multiple columns (issue #149, PR #151). diff --git a/src/alchemlyb/__init__.py b/src/alchemlyb/__init__.py index 363a4f4c..061e2fe2 100644 --- a/src/alchemlyb/__init__.py +++ b/src/alchemlyb/__init__.py @@ -47,7 +47,11 @@ def concat(objs, *args, **kwargs): .. versionadded:: 0.5.0''' # Sanity check - attrs = objs[0].attrs + try: + attrs = objs[0].attrs + except IndexError: # except empty list as input + raise ValueError('No objects to concatenate') + for obj in objs: if attrs != obj.attrs: raise ValueError('All pandas objects should have the same attrs.') diff --git a/src/alchemlyb/tests/test_units.py b/src/alchemlyb/tests/test_units.py index 19014656..6e9ee343 100644 --- a/src/alchemlyb/tests/test_units.py +++ b/src/alchemlyb/tests/test_units.py @@ -33,6 +33,11 @@ def test_concat(): with pytest.raises(ValueError): alchemlyb.concat([df1, df2]) +def test_concat_empty(): + '''Test if empty raise the right error.''' + with pytest.raises(ValueError): + alchemlyb.concat([]) + def test_setT(): '''Test setting temperature.''' df = pd.DataFrame(data={'col1': [1, 2]})