Repository: ecmwf/earthkit-data
Pull request #455 (2024-09-16 12:12:24)

Implement repr to ArrayField
This PR implements the repr for an ArrayField.  E.g. if `f` contains surface data:

```python
print(f)
>>> ArrayField(2t,None,20200513,1200,0,0)
```

Note: this repr is GRIB specific.

codecov-commenter: ## [Codecov](https://app.codecov.io/gh/ecmwf/earthkit-data/pull/455?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecmwf) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 90.56%. Comparing base [(`59fc21b`)](https://app.codecov.io/gh/ecmwf/earthkit-data/commit/59fc21b8dba8c3266617ffe58dda1ac9110a26f7?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecmwf) to head [(`c179576`)](https://app.codecov.io/gh/ecmwf/earthkit-data/commit/c17957659173ce7ec256996c877850825cf866a5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecmwf).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff            @@
##           develop     #455   +/-   ##
========================================
  Coverage    90.56%   90.56%           
========================================
  Files          123      123           
  Lines         8329     8333    +4     
  Branches       701      701           
========================================
+ Hits          7543     7547    +4     
  Misses         655      655           
  Partials       131      131           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/ecmwf/earthkit-data/pull/455?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecmwf).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ecmwf).


Patch:
diff --git a/src/earthkit/data/sources/array_list.py b/src/earthkit/data/sources/array_list.py
index b56bc82..c4bd6b4 100644
--- a/src/earthkit/data/sources/array_list.py
+++ b/src/earthkit/data/sources/array_list.py
@@ -46,7 +46,14 @@ class ArrayField(Field):
             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.


Test patch:
diff --git a/tests/array_fieldlist/test_numpy_fs_metadata.py b/tests/array_fieldlist/test_numpy_fs_metadata.py
index 64abd89..a6b44b6 100644
--- a/tests/array_fieldlist/test_numpy_fs_metadata.py
+++ b/tests/array_fieldlist/test_numpy_fs_metadata.py
@@ -23,6 +23,13 @@ from array_fl_fixtures import load_array_fl_file  # noqa: E402
 # 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)