ert icon indicating copy to clipboard operation
ert copied to clipboard

Trivial initialization of NumericalRecord does not work

Open berland opened this issue 3 years ago • 2 comments

Describe the bug Based on the docstring and typing information for a NumericalRecord it should be possible to initialize an object like

ert.data.NumericalRecord(data=[1,2,3], index=("a", "b", "c"))

but this ends in an error:

Traceback (most recent call last):
  File "test_numdirect.py", line 6, in <module>
    NumericalRecord(data=[1,2,3], index=("a", "b", "c"))
  File "/work/projects/ert/ert/data/record/_record.py", line 165, in __init__
    self._validate_index(data, index)
  File "/work/projects/ert/ert/data/record/_record.py", line 191, in _validate_index
    f"inconsistent index {norm_record_index} vs {index}"
ert.data.record._record.RecordValidationError: inconsistent index (0, 1, 2) vs ('a', 'b', 'c')

This is due to the index validation code that always infers the index from the data arg.

A consequence of this is f.ex that code in _stats.py that knows both the data and the index need to construct a dictionary as a temporary object in order to initialize a record.

berland avatar Feb 16 '22 09:02 berland

Tests indicate that it is an intention to make this fail: NumericalRecord(data=[1,2,3], index=(0,1,5)) which means that the role of the index argument in the API is not to give the user explicit control over the index of the data.

berland avatar Feb 16 '22 11:02 berland

I would suggest to remove the index argument as it's quite redundant since the index is always built; i.e. inferred from the data as described :top:.

xjules avatar Feb 16 '22 11:02 xjules

Closing this as NumericalRecord has been removed as part of removing all remnants of ert3

oyvindeide avatar Dec 05 '23 08:12 oyvindeide