Skip to content

Commit

Permalink
Merge pull request #3430 from scipp/fix-group-auto-groups-str
Browse files Browse the repository at this point in the history
Fix `group` with automatic groups by labels of str dtype
  • Loading branch information
SimonHeybrock committed May 14, 2024
2 parents 25d6577 + 3ac6119 commit 3cb2e66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/scipp/core/binning.py
Expand Up @@ -704,7 +704,7 @@ def _make_groups(x, arg):
if coord.bins is not None:
coord = coord.copy().bins.constituents['data']

if coord.values.size == 0:
if 0 in coord.shape:
unique = coord.values[0:0]
# We are currently using np.unique to find all unique groups. This can be very slow
# for large inputs. In many cases groups are in a bounded range of integers, and we
Expand Down
8 changes: 8 additions & 0 deletions tests/binning_test.py
Expand Up @@ -1068,3 +1068,11 @@ def test_noncontiguous_int_grouping():
assert contiguous_idx.values.data.contiguous

assert_identical(table.group(nonnontiguous_idx), table.group(contiguous_idx))


def test_group_automatic_groups_works_with_string_coord():
keys = sc.array(dims=['row'], values=['a', 'b', 'c', 'a', 'b', 'c'])
table = sc.DataArray(sc.ones(dims=['row'], shape=[6]), coords={'key': keys})
assert sc.identical(
table.group('key').coords['key'], sc.array(dims=['key'], values=['a', 'b', 'c'])
)

0 comments on commit 3cb2e66

Please sign in to comment.