Skip to content
forked from pydata/xarray

Commit

Permalink
Merge branch 'main' into rolling-auto-rechunk
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian authored Nov 15, 2024
2 parents 2431005 + 9f459c3 commit b8520bd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Bug fixes
By `Pascal Bourgault <https://github.com/aulemahal>`_.
- Fix CF decoding of ``grid_mapping`` to allow all possible formats, add tests (:issue:`9761`, :pull:`9765`).
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
- Add `User-Agent` to request-headers when retrieving tutorial data (:issue:`9774`, :pull:`9782`)
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
17 changes: 9 additions & 8 deletions xarray/backends/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ def _find_absolute_paths(
def _normalize_path_list(
lpaths: NestedSequence[str | os.PathLike],
) -> NestedSequence[str]:
return [
(
_normalize_path(p)
if isinstance(p, str | os.PathLike)
else _normalize_path_list(p)
)
for p in lpaths
]
paths = []
for p in lpaths:
if isinstance(p, str | os.PathLike):
paths.append(_normalize_path(p))
elif isinstance(p, list):
paths.append(_normalize_path_list(p)) # type: ignore[arg-type]
else:
paths.append(p) # type: ignore[arg-type]
return paths

return _normalize_path_list(paths)

Expand Down
2 changes: 2 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -5511,6 +5511,8 @@ def test_source_encoding_always_present_with_fsspec() -> None:
fs = fsspec.filesystem("file")
with fs.open(tmp) as f, open_dataset(f) as ds:
assert ds.encoding["source"] == tmp
with fs.open(tmp) as f, open_mfdataset([f]) as ds:
assert "foo" in ds


def _assert_no_dates_out_of_range_warning(record):
Expand Down
8 changes: 7 additions & 1 deletion xarray/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import os
import pathlib
import sys
from typing import TYPE_CHECKING

import numpy as np
Expand Down Expand Up @@ -157,8 +158,13 @@ def open_dataset(

url = f"{base_url}/raw/{version}/{path.name}"

headers = {"User-Agent": f"xarray {sys.modules['xarray'].__version__}"}
downloader = pooch.HTTPDownloader(headers=headers)

# retrieve the file
filepath = pooch.retrieve(url=url, known_hash=None, path=cache_dir)
filepath = pooch.retrieve(
url=url, known_hash=None, path=cache_dir, downloader=downloader
)
ds = _open_dataset(filepath, engine=engine, **kws)
if not cache:
ds = ds.load()
Expand Down

0 comments on commit b8520bd

Please sign in to comment.