larray-project / larray

N-dimensional labelled arrays in Python
https://larray.readthedocs.io/
GNU General Public License v3.0
8 stars 6 forks source link

Axis.difference(scalar_group) and Axis.difference([scalar_index_group]) fail silently #1104

Closed gdementen closed 4 months ago

gdementen commented 7 months ago
>>> a = la.Axis('a=a0..a2')

The following work fine:

>>> a.difference('a0')
Axis(['a1', 'a2'], 'a')
>>> a.difference(a.i[[0]])
Axis(['a1', 'a2'], 'a')
>>> a.difference(a[['a0']])
Axis(['a1', 'a2'], 'a')
>>> a.difference([a['a0']])
Axis(['a1', 'a2'], 'a')

But all the following do not:

>>> a.difference(a['a0'])
Axis(['a0', 'a1', 'a2'], 'a')
>>> a.difference(a.i[0])
Axis(['a0', 'a1', 'a2'], 'a')
>>> a.difference([a.i[0]])
Axis(['a0', 'a1', 'a2'], 'a')

priority high even though this is seldom used because it is a silent failure. There is most likely the same problem in Axis.intersection and Axis.union.

I am unsure all those cases should be supported but the asymmetry between string and groups, or even LGroup and IGroup is puzzling, and the unsupported cases (if any) must fail loudly instead of silently.

gdementen commented 7 months ago

FWIW, when doing the operation on a Group (instead of on the Axis), most cases work ?!?

>>> a[:].difference(a.i[0])
a['a1', 'a2'].set()
>>> a[:].difference(a.i[[0]])
a['a1', 'a2'].set()
>>> a[:].difference(a['a0'])
a['a1', 'a2'].set()
>>> a[:].difference('a0')
a['a1', 'a2'].set()
>>> a[:].difference([a['a0']])
a['a1', 'a2'].set()

Except:

>>> a[:].difference([a.i[0]])
a['a0', 'a1', 'a2'].set()