From fe1a294e28d4e918d9e748ab7a9b48d0bee85675 Mon Sep 17 00:00:00 2001 From: Sandor Kertesz Date: Mon, 16 Sep 2024 13:41:20 +0100 Subject: [PATCH] Implement repr to ArayField (#455) --- src/earthkit/data/sources/array_list.py | 9 ++++++++- tests/array_fieldlist/test_numpy_fs_metadata.py | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/earthkit/data/sources/array_list.py b/src/earthkit/data/sources/array_list.py index b56bc82d..c4bd6b4b 100644 --- a/src/earthkit/data/sources/array_list.py +++ b/src/earthkit/data/sources/array_list.py @@ -46,7 +46,14 @@ def _values(self, dtype=None): return self.array_backend.array_ns.astype(self._array, dtype, copy=False) def __repr__(self): - return f"{self.__class__.__name__}()" + return self.__class__.__name__ + "(%s,%s,%s,%s,%s,%s)" % ( + self._metadata.get("shortName", None), + self._metadata.get("levelist", None), + self._metadata.get("date", None), + self._metadata.get("time", None), + self._metadata.get("step", None), + self._metadata.get("number", None), + ) def write(self, f, **kwargs): r"""Write the field to a file object. diff --git a/tests/array_fieldlist/test_numpy_fs_metadata.py b/tests/array_fieldlist/test_numpy_fs_metadata.py index 64abd89c..a6b44b62 100644 --- a/tests/array_fieldlist/test_numpy_fs_metadata.py +++ b/tests/array_fieldlist/test_numpy_fs_metadata.py @@ -23,6 +23,13 @@ # See grib/test_grib_metadata.py +def test_array_fl_field_repr(): + ds, _ = load_array_fl(1) + + t = repr(ds[0]) + assert t == "ArrayField(2t,None,20200513,1200,0,0)" + + def test_array_fl_values_metadata_basic(): ds, _ = load_array_fl(1)