Skip to content

Commit 80080dc

Browse files
committed
fix indexing error due to inproper filter of None slices
1 parent d7431d7 commit 80080dc

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

docs/user-guide/subset.ipynb

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": null,
2423
"metadata": {
25-
"ExecuteTime": {
26-
"end_time": "2025-08-06T02:06:43.989811Z",
27-
"start_time": "2025-08-06T02:06:43.930068Z"
28-
},
2924
"collapsed": false,
3025
"jupyter": {
3126
"outputs_hidden": false
27+
},
28+
"ExecuteTime": {
29+
"end_time": "2025-09-15T15:36:11.058925Z",
30+
"start_time": "2025-09-15T15:36:10.649951Z"
3231
}
3332
},
34-
"outputs": [],
3533
"source": [
3634
"import warnings\n",
3735
"\n",
@@ -45,7 +43,21 @@
4543
"plot_opts = {\"width\": 700, \"height\": 350}\n",
4644
"hv.extension(\"bokeh\")\n",
4745
"warnings.filterwarnings(\"ignore\")"
48-
]
46+
],
47+
"outputs": [
48+
{
49+
"ename": "ModuleNotFoundError",
50+
"evalue": "No module named 'geocat'",
51+
"output_type": "error",
52+
"traceback": [
53+
"\u001B[31m---------------------------------------------------------------------------\u001B[39m",
54+
"\u001B[31mModuleNotFoundError\u001B[39m Traceback (most recent call last)",
55+
"\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[1]\u001B[39m\u001B[32m, line 4\u001B[39m\n\u001B[32m 1\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mwarnings\u001B[39;00m\n\u001B[32m 3\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mcartopy\u001B[39;00m\u001B[34;01m.\u001B[39;00m\u001B[34;01mcrs\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mccrs\u001B[39;00m\n\u001B[32m----> \u001B[39m\u001B[32m4\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mgeocat\u001B[39;00m\u001B[34;01m.\u001B[39;00m\u001B[34;01mdatafiles\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mgeodf\u001B[39;00m\n\u001B[32m 5\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mgeoviews\u001B[39;00m\u001B[34;01m.\u001B[39;00m\u001B[34;01mfeature\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mgf\u001B[39;00m\n\u001B[32m 6\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mholoviews\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mhv\u001B[39;00m\n",
56+
"\u001B[31mModuleNotFoundError\u001B[39m: No module named 'geocat'"
57+
]
58+
}
59+
],
60+
"execution_count": 1
4961
},
5062
{
5163
"cell_type": "markdown",

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ extend-exclude = ["test","benchmarks"]
7676

7777
[tool.ruff.lint]
7878
extend-select = ["I"]
79+
extend-ignore = ["E731"]
7980

8081
[tool.ruff.lint.isort]
8182
known-first-party = ["uxarray"]

test/core/test_inheritance.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,14 @@ def test_isel_non_grid_dim(self, ds):
211211

212212
assert ds_t_multi.uxgrid == ds.uxgrid
213213
assert ds_t_multi.sizes['time'] == 2
214+
215+
def test_subscription(self, ds):
216+
217+
# index time dimension
218+
res_t = ds['fc'][0]
219+
220+
assert isinstance(res_t, ux.UxDataArray)
221+
222+
# index grid dimension
223+
res_f = ds['fc'][:, 0]
224+
assert isinstance(res_f, ux.UxDataArray)

uxarray/core/utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,22 @@ def _validate_indexers(indexers, indexers_kwargs, func_name, ignore_grid):
8787

8888
from uxarray.constants import GRID_DIMS
8989

90+
# Used to filter out slices containing all Nones (causes subscription errors, i.e., var[0])
91+
_is_full_none_slice = (
92+
lambda v: isinstance(v, slice)
93+
and v.start is None
94+
and v.stop is None
95+
and v.step is None
96+
)
97+
9098
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, func_name)
91-
grid_dims = set(GRID_DIMS).intersection(indexers)
99+
100+
# Only count a grid dim if its indexer is NOT a no-op full slice
101+
grid_dims = {
102+
dim
103+
for dim in GRID_DIMS
104+
if dim in indexers and not _is_full_none_slice(indexers[dim])
105+
}
92106

93107
if not ignore_grid and len(grid_dims) > 1:
94108
raise ValueError(

0 commit comments

Comments
 (0)