File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 11from collections import defaultdict
2- from typing import List , Optional
2+ from typing import List , Optional , Union
33
44import numpy as np
55import 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 ,
Original file line number Diff line number Diff 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 )]
You can’t perform that action at this time.
0 commit comments