diff --git a/doc/source/changes/version_0_34.rst.inc b/doc/source/changes/version_0_34.rst.inc index 2ff32e45f..286cfa002 100644 --- a/doc/source/changes/version_0_34.rst.inc +++ b/doc/source/changes/version_0_34.rst.inc @@ -18,6 +18,17 @@ Backward incompatible changes New features ^^^^^^^^^^^^ +* allow ";" in __getitem__ and __setitem__ strings, making it possible to specify keys for several axes in a single + string (closes :issue:`904`). For example: + + >>> arr = ndtest((2, 3)) + >>> arr + a\b b0 b1 b2 + a0 0 1 2 + a1 3 4 5 + >>> arr['a1;b2'] + 5 + * added a feature (see the :ref:`miscellaneous section ` for details). It works on :ref:`api-axis` and :ref:`api-group` objects. diff --git a/larray/core/axis.py b/larray/core/axis.py index 5d342bd61..ef864525e 100644 --- a/larray/core/axis.py +++ b/larray/core/axis.py @@ -2811,6 +2811,12 @@ def _key_to_axis_indices_dict(self, key): """ from .array import Array + if isinstance(key, str) and ';' in key: + # FIXME: it would be more logical to use _to_keys(key) instead but this breaks + # the "target an aggregate with its key" feature (test_getitem_on_group_agg). + # It might be a good thing though as it costs so much for so little use. + # key = _to_keys(key) + key = tuple(key.split(';')) if isinstance(key, dict): # key axes could be strings or axis references and we want real axes key = tuple(self[axis][axis_key] for axis, axis_key in key.items()) diff --git a/larray/tests/test_array.py b/larray/tests/test_array.py index 69a4dbab2..df78a4a25 100644 --- a/larray/tests/test_array.py +++ b/larray/tests/test_array.py @@ -651,6 +651,14 @@ def test_getitem_guess_axis(array): res = arr['b[l1]'] assert_array_equal(res, arr.data[:, 0]) + # several axes in same string (guess axis) + res = arr['l0;l2'] + assert res == 1 + + # several axes in same string (with axis information) + res = arr['a[l1];b[l2]'] + assert res == 3 + def test_getitem_positional_group(array): raw = array.data