Skip to content

Commit c4406ba

Browse files
committed
allow single str for load_grid field
1 parent 7e1dfea commit c4406ba

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

yt_xarray/accessor/accessor.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections import defaultdict
2-
from typing import List, Optional
2+
from typing import List, Optional, Union
33

44
import numpy as np
55
import xarray as xr
@@ -22,7 +22,7 @@ def __init__(self, xarray_obj):
2222

2323
def load_grid(
2424
self,
25-
fields: Optional[List[str]] = None,
25+
fields: Optional[Union[str, List[str]]] = None,
2626
geometry: str = None,
2727
use_callable: bool = True,
2828
sel_dict: Optional[dict] = None,
@@ -35,7 +35,7 @@ def load_grid(
3535
3636
Parameters
3737
----------
38-
fields : list[str]
38+
fields : str, list[str]
3939
list of fields to include. If None, will try to use all fields
4040
4141
geometry : str
@@ -66,6 +66,11 @@ def load_grid(
6666
# might as well try!
6767
fields = list(self._obj.data_vars)
6868

69+
if isinstance(fields, str):
70+
fields = [
71+
fields,
72+
]
73+
6974
sel_info = _xr_to_yt.Selection(
7075
self._obj,
7176
fields=fields,

yt_xarray/tests/test_accesor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,8 @@ def test_stretched_grid(use_callable):
221221
cell_centers = (dims[:-1] + dims[1:]) / 2
222222
dimvals = np.unique(ad[("index", dim)].d)
223223
assert np.all(dimvals == cell_centers)
224+
225+
def test_load_single_field(ds_xr):
226+
flds = "a_new_field_0"
227+
ds_yt = ds_xr.yt.load_grid(flds)
228+
_ = ds_yt.all_data()[("stream", flds)]

0 commit comments

Comments
 (0)