Skip to content

Commit 740e086

Browse files
authored
Merge pull request #67 from chrishavlin/single_field_load_grid
allow single field for load_grid
2 parents 7e1dfea + c3d5318 commit 740e086

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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)]

0 commit comments

Comments
 (0)