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
9 changes: 9 additions & 0 deletions docs/release_notes/version_0.15_updates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ Version 0.15 Updates
/////////////////////////


Version 0.15.1
===============

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

- Fixed issue when :func:`xarray.open_dataset` did not work with the "earthkit" engine when a ``pathlib.Path`` object specified the input data (:pr:`741`).


Version 0.15.0
===============

Expand Down
5 changes: 4 additions & 1 deletion src/earthkit/data/utils/xarray/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,14 @@ def guess_can_open(cls, filename_or_obj):

@staticmethod
def _fieldlist(filename_or_obj, source_type):
import os
import pathlib

from earthkit.data.core import Base

if isinstance(filename_or_obj, Base):
ds = filename_or_obj
elif isinstance(filename_or_obj, str):
elif isinstance(filename_or_obj, (str, os.PathLike, pathlib.Path)):
from earthkit.data import from_source

ds = from_source(source_type, filename_or_obj)
Expand Down
41 changes: 19 additions & 22 deletions tests/xr_engine/test_xr_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#

import os
import pathlib
import sys

import numpy as np
Expand All @@ -36,32 +37,28 @@ def test_xr_engine_kwargs_unchanged(engine):


@pytest.mark.cache
@pytest.mark.parametrize(
"file",
[
"pl.grib",
# "era5-levels-members",
# "fields_with_missing_values",
# "lambert_grid",
# "reduced_gg",
# "regular_gg_sfc",
# "regular_gg_pl",
# "regular_gg_ml",
# "regular_gg_ml_g2",
# "regular_ll_sfc",
# "regular_ll_msl",
# "scanning_mode_64",
# "single_gridpoint",
# "spherical_harmonics",
# "t_analysis_and_fc_0",
],
)
def test_xr_engine_basic(file):
ds = from_source("url", earthkit_remote_test_data_file("test-data", "xr_engine", "level", file))
def test_xr_engine_basic():
ds = from_source("url", earthkit_remote_test_data_file("test-data", "xr_engine", "level", "pl.grib"))
res = ds.to_xarray()
assert res is not None


@pytest.mark.cache
@pytest.mark.parametrize("path_maker", [lambda x: x, lambda x: pathlib.Path(x)])
def test_xr_engine_open_dataset_path(path_maker):

ds = from_source("sample", "pl.grib")
path = path_maker(ds.path)

import xarray as xr

res = xr.open_dataset(
path,
engine="earthkit",
)
assert res is not None


@pytest.mark.cache
@pytest.mark.parametrize("api", ["earthkit", "xr"])
def test_xr_engine_detailed_check_1(api):
Expand Down
Loading