File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed
Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change 22
33[ ![ PyPI version] ( https://badge.fury.io/py/yt_xarray.svg )] ( https://badge.fury.io/py/yt_xarray )
44[ ![ Python Version] ( https://img.shields.io/pypi/pyversions/yt_xarray.svg?color=green )] ( https://python.org )
5+ [ ![ Tests] ( https://github.com/data-exp-lab/yt_xarray/actions/workflows/run-pytest-tests.yml/badge.svg )] ( https://github.com/data-exp-lab/yt_xarray/actions/workflows/run-pytest-tests.yml )
56[ ![ codecov] ( https://codecov.io/gh/data-exp-lab/yt_xarray/branch/main/graph/badge.svg )] ( https://codecov.io/gh/data-exp-lab/yt_xarray )
67[ ![ pre-commit.ci status] ( https://results.pre-commit.ci/badge/github/data-exp-lab/yt_xarray/main.svg )] ( https://results.pre-commit.ci/latest/github/data-exp-lab/yt_xarray/main )
78
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,9 @@ 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+
226+ def test_load_single_field (ds_xr ):
227+ flds = "a_new_field_0"
228+ ds_yt = ds_xr .yt .load_grid (flds )
229+ _ = ds_yt .all_data ()[("stream" , flds )]
You can’t perform that action at this time.
0 commit comments