Skip to content

Commit a935fd4

Browse files
Fix: allow : characters in xarray reader's sel parameter (#1336)
* add failing test * fix: allow : characters in xarray sel parameters resolves #1335 * chore: update changelog * add one more test * add one more test * update changelog --------- Co-authored-by: vincentsarago <vincent.sarago@gmail.com>
1 parent 0b58b8b commit a935fd4

4 files changed

Lines changed: 31 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
* change: rio-tiler requirement to `>=9.0.0rc2,<10.0`
88

9+
### titiler.xarray
10+
11+
* fix: allow `:` characters in xarray reader's `sel` parameter (e.g. for timestamps) (https://github.com/developmentseed/titiler/pull/1336)
12+
913
### titiler.mosaic
1014

1115
* fix: `pixel-selection` method initialization to avoid FastAPI caching (author @raster-blaster, https://github.com/developmentseed/titiler/pull/1334)

src/titiler/xarray/tests/test_dependencies.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,18 @@ def endpoint(
5757
response = client.get("/", params={"sel": ["yo=nearest::yo", "ye=ye"]})
5858
params = response.json()
5959
assert params == {"sel": ["yo=nearest::yo", "ye=ye"]}
60+
61+
response = client.get(
62+
"/", params={"sel": ["yo=nearest::2023-01-01T00:00:00", "ye=ye"]}
63+
)
64+
params = response.json()
65+
assert params == {"sel": ["yo=nearest::2023-01-01T00:00:00", "ye=ye"]}
66+
67+
response = client.get(
68+
"/", params={"sel": ["yo=2023-01-01T00:00:00::nearest", "ye=ye"]}
69+
)
70+
assert response.status_code == 422
71+
72+
response = client.get("/", params={"sel": ["yo=2023-01-01T00:00:00", "ye=ye"]})
73+
params = response.json()
74+
assert params == {"sel": ["yo=2023-01-01T00:00:00", "ye=ye"]}

src/titiler/xarray/tests/test_io_tools.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,17 @@ def test_io_open_zarr(src_path, options):
384384
{"dimension": "level", "values": ["10"], "method": "nearest"},
385385
],
386386
),
387+
(
388+
["time=nearest::2022-01-01T00:00:00", "level=nearest::10"],
389+
[
390+
{
391+
"dimension": "time",
392+
"values": ["2022-01-01T00:00:00"],
393+
"method": "nearest",
394+
},
395+
{"dimension": "level", "values": ["10"], "method": "nearest"},
396+
],
397+
),
387398
([], []),
388399
],
389400
)

src/titiler/xarray/titiler/xarray/dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class XarrayIOParams(DefaultDependency):
3535
SelDimStr = Annotated[
3636
str,
3737
StringConstraints(
38-
pattern=r"^[^=]+=((nearest|pad|ffill|backfill|bfill)::)?[^=::]+$"
38+
pattern=r"^[^=]+=((nearest|pad|ffill|backfill|bfill)::)?([^=:]|:[^:])+$"
3939
),
4040
]
4141

0 commit comments

Comments
 (0)