Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions docs/examples/files.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/cgr/git/earthkit-data/src/earthkit/data/readers/netcdf/fieldlist.py:318: FutureWarning: In a future version of xarray decode_timedelta will default to False rather than None. To silence this warning, set decode_timedelta to True, False, or a 'CFTimedeltaCoder' instance.\n",
" return xr.open_dataset(self.path_or_url)\n"
]
},
{
"data": {
"text/html": [
Expand Down Expand Up @@ -508,10 +516,9 @@
}
],
"source": [
"\n",
"fs = ekd.from_source(\"file-pattern\", \"./test{id}.grib\",\n",
"ds = ekd.from_source(\"file-pattern\", \"./test{id}.grib\",\n",
" {\"id\": [4, 6]})\n",
"fs.ls()"
"ds.ls()"
]
},
{
Expand All @@ -531,9 +538,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "dev_ecc",
"display_name": "dev",
"language": "python",
"name": "dev_ecc"
"name": "dev"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -545,7 +552,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.11.12"
}
},
"nbformat": 4,
Expand Down
9 changes: 9 additions & 0 deletions docs/release_notes/version_0.14_updates.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
Version 0.14 Updates
/////////////////////////

Version 0.14.2
===============

Fixes
+++++++++++++++++

- Fixed issue when the :ref:`data-sources-file-pattern` source did not return the right data object when the ``hive_partitioning`` option was set to ``False`` (:pr:`697`).
- Fixed issue when disabling the ``add_earthkit_attrs`` option in :py:meth:`~data.readers.grib.index.GribFieldList.to_xarray` caused a crash (:pr:`696`).


Version 0.14.1
===============
Expand Down
2 changes: 1 addition & 1 deletion src/earthkit/data/sources/file_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def mutate(self) -> Union["HiveFilePattern", "FilePattern"]:
if self.hive_partitioning:
return HiveFilePattern(self.pattern, self.params)
else:
return self
return super().mutate()


source = FilePattern
2 changes: 1 addition & 1 deletion src/earthkit/data/utils/xarray/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def prepare_tensor(self, ds, dims, name):
elif num > 1 or not self.profile.dims.squeeze or d.name in self.profile.dims.ensure_dims:
tensor_dims.append(d)
tensor_coords[d.key] = vals[d.key]
if d.key in component_vals:
if component_vals and d.key in component_vals:
tensor_coords_component[d.key] = component_vals[d.key]

# check if the dims/coords are consistent with the tensors of
Expand Down
21 changes: 21 additions & 0 deletions tests/sources/test_file_pattern.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

# (C) Copyright 2020 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#


from earthkit.data import from_source
from earthkit.data.testing import earthkit_examples_file


def test_file_pattern_source_grib():
ds = from_source("file-pattern", earthkit_examples_file("test{id}.grib"), {"id": [4, 6]})

assert len(ds) == 10
assert ds.metadata("param") == ["t", "z", "t", "z", "t", "u", "v", "t", "u", "v"]
15 changes: 14 additions & 1 deletion tests/xr_engine/test_xr_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def test_xr_engine_single_field():

@pytest.mark.cache
@pytest.mark.parametrize("add", [False, True])
def test_xr_engine_add_earthkit_attrs(add):
def test_xr_engine_add_earthkit_attrs_1(add):
ds_ek = from_source("url", earthkit_remote_test_data_file("test-data/xr_engine/level/pl.grib"))
ds_ek = ds_ek[0]

Expand All @@ -558,3 +558,16 @@ def test_xr_engine_add_earthkit_attrs(add):
assert "_earthkit" in ds["t"].attrs
else:
assert "_earthkit" not in ds["t"].attrs


@pytest.mark.cache
def test_xr_engine_add_earthkit_attrs_2():
ds_ek = from_source("url", earthkit_remote_test_data_file("test-data/xr_engine/level/pl.grib"))
ds_ek = ds_ek[0]

ds = ds_ek.to_xarray(
add_earthkit_attrs=False,
)

assert ds
assert "_earthkit" not in ds["t"].attrs
Loading