Skip to content

Commit

Permalink
make alchemlyb.concat behave like pd.concat (PR #152)
Browse files Browse the repository at this point in the history
* fix #150
* `alchemlyb.concat([])` now raises ValueError (like pandas.concat())
* Update CHANGES
* add test
  • Loading branch information
xiki-tempula committed Jul 13, 2021
1 parent d4e6bea commit eaafdb3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
6 changes: 5 additions & 1 deletion src/alchemlyb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
5 changes: 5 additions & 0 deletions src/alchemlyb/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]})
Expand Down

0 comments on commit eaafdb3

Please sign in to comment.