Skip to content

Commit 88e8cbe

Browse files
authored
Merge pull request #4 from chrishavlin/callable_experiment
yt ds from within accessor using callable
2 parents bd2220c + fb5f517 commit 88e8cbe

File tree

11 files changed

+226
-67
lines changed

11 files changed

+226
-67
lines changed

.github/workflows/build-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: Run tests
22

3-
on: [push, pull_request]
3+
on: [pull_request]
44

55
jobs:
66
build:
77

88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: [3.7, 3.8]
11+
python-version: ['3.8', '3.9', '3.10']
1212

1313
steps:
1414
- uses: actions/checkout@v2

.github/workflows/check-manifest.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ jobs:
1616
run: |
1717
python -m pip install --upgrade pip
1818
python -m pip install check-manifest
19+
- name: install build dependencies
20+
run: |
21+
python -m pip install wheel
1922
- name: Install yt_xarray
2023
shell: bash
2124
run: |

.github/workflows/style-checks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
id: black
3939
run: |
4040
black --version
41-
black --check --diff yt_idv/
41+
black --check --diff yt_xarray/
4242
4343
isort:
4444
name: isort
@@ -57,7 +57,7 @@ jobs:
5757
id: isort
5858
run: |
5959
isort --version-number
60-
isort . --check --diff
60+
isort yt_xarray --check --diff
6161
6262
flynt:
6363
name: flynt

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/ambv/black
3-
rev: 19.10b0 # keep in sync with tests/lint_requirements.txt
3+
rev: 22.8.0 # keep in sync with tests/lint_requirements.txt
44
hooks:
55
- id: black
66
language_version: python3

MANIFEST.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ include CONTRIBUTING.rst
33
include HISTORY.rst
44
include LICENSE
55
include README.rst
6-
6+
include *.txt
7+
include *.yaml
8+
include Makefile
9+
include tox.ini
710
recursive-include tests *
811
recursive-exclude * __pycache__
912
recursive-exclude * *.py[co]
13+
exclude .editorconfig
1014

1115
recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif

setup.cfg

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,3 @@ ignore = E203, # Whitespace before ':' (black compatibility)
2828
E741, # Do not use variables named 'I', 'O', or 'l'
2929
W503, # Line break occurred before a binary operator (black compatibility)
3030

31-
[tool:pytest]
32-
collect_ignore = ['setup.py']

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
setup(
2323
author="Chris Havlin",
2424
author_email="[email protected]",
25-
python_requires=">=3.6",
25+
python_requires=">=3.8",
2626
classifiers=[
2727
"Development Status :: 2 - Pre-Alpha",
2828
"Intended Audience :: Developers",
2929
"License :: OSI Approved :: MIT License",
3030
"Natural Language :: English",
3131
"Programming Language :: Python :: 3",
32-
"Programming Language :: Python :: 3.6",
33-
"Programming Language :: Python :: 3.7",
3432
"Programming Language :: Python :: 3.8",
33+
"Programming Language :: Python :: 3.9",
34+
"Programming Language :: Python :: 3.10",
3535
],
3636
description="interfaces between yt and xarray",
3737
install_requires=requirements,

tests/lint_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ mccabe~=0.6.1
33
pycodestyle~=2.6.0
44
pyflakes~=2.2.0
55
isort==5.6.4 # keep in sync with .pre-commit-config.yaml
6-
black==19.10b0 # keep in sync with .pre-commit-config.yaml
6+
black==22.8.0 # keep in sync with .pre-commit-config.yaml
77
flake8-bugbear
88
flynt==0.52 # keep in sync with .pre-commit-config.yaml

tests/test_accesor.py

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
import numpy as np
2+
import pytest
3+
import yt
24

35
import yt_xarray # noqa: F401
46
from yt_xarray._utilities import construct_minimal_ds
57

68

9+
@pytest.fixture()
10+
def ds_xr():
11+
# a base xarray ds to be used in various places.
12+
tfield = "a_new_field"
13+
n_x = 3
14+
n_y = 4
15+
n_z = 5
16+
ds = construct_minimal_ds(
17+
field_name=tfield,
18+
n_fields=3,
19+
n_x=n_x,
20+
n_y=n_y,
21+
n_z=n_z,
22+
z_name="depth",
23+
coord_order=["z", "y", "x"],
24+
)
25+
return ds
26+
27+
728
def test_accessor():
829

930
tfield = "a_new_field"
@@ -69,33 +90,23 @@ def test_bbox():
6990
# the test dataset.
7091

7192

72-
def test_load_uniform_grid():
93+
def test_load_uniform_grid(ds_xr):
7394

74-
tfield = "a_new_field"
75-
n_x = 3
76-
n_y = 4
77-
n_z = 5
78-
ds = construct_minimal_ds(
79-
field_name=tfield,
80-
n_fields=3,
81-
n_x=n_x,
82-
n_y=n_y,
83-
n_z=n_z,
84-
z_name="depth",
85-
coord_order=["z", "y", "x"],
86-
)
87-
88-
flds = [tfield + "_0", tfield + "_1"]
89-
ds_yt = ds.yt.load_uniform_grid(flds)
95+
flds = ["a_new_field_0", "a_new_field_1"]
96+
ds_yt = ds_xr.yt.load_uniform_grid(flds)
9097
assert ds_yt.coordinates.name == "internal_geographic"
9198
expected_field_list = [("stream", f) for f in flds]
9299
assert all([f in expected_field_list] for f in ds_yt.field_list)
93100

94-
ds_yt = ds.yt.ds # should generate a ds with all fields
95-
flds = [tfield + "_0", tfield + "_1", tfield + "_2"]
101+
ds_yt = ds_xr.yt.load_uniform_grid() # should generate a ds with all fields
102+
flds = flds + [
103+
"a_new_field_2",
104+
]
96105
expected_field_list = [("stream", f) for f in flds]
97106
assert all([f in expected_field_list] for f in ds_yt.field_list)
98107

108+
tfield = "nice_field"
109+
n_x, n_y, n_z = (7, 5, 17)
99110
ds = construct_minimal_ds(
100111
field_name=tfield,
101112
n_fields=3,
@@ -105,7 +116,7 @@ def test_load_uniform_grid():
105116
z_name="altitude",
106117
coord_order=["z", "y", "x"],
107118
)
108-
ds_yt = ds.yt.ds
119+
ds_yt = ds.yt.load_uniform_grid()
109120
assert ds_yt.coordinates.name == "geographic"
110121
assert all([f in expected_field_list] for f in ds_yt.field_list)
111122

@@ -120,6 +131,35 @@ def test_load_uniform_grid():
120131
y_name="y",
121132
coord_order=["z", "y", "x"],
122133
)
134+
flds = [
135+
tfield + "_0",
136+
]
123137
ds_yt = ds.yt.load_uniform_grid(flds, length_unit="km")
124138
assert ds_yt.coordinates.name == "cartesian"
125139
assert all([f in expected_field_list] for f in ds_yt.field_list)
140+
141+
142+
@pytest.mark.skipif(
143+
yt.__version__.startswith("4.1") is False, reason="requires yt>=4.1.0"
144+
)
145+
def test_load_grid_from_callable(ds_xr):
146+
ds = ds_xr.yt.load_grid_from_callable()
147+
flds = list(ds_xr.data_vars)
148+
for fld in flds:
149+
assert ("stream", fld) in ds.field_list
150+
151+
f = ds.all_data()[flds[0]]
152+
assert len(f) == ds_xr.data_vars[flds[0]].size
153+
154+
155+
@pytest.mark.skipif(
156+
yt.__version__.startswith("4.1") is False, reason="requires yt>=4.1.0"
157+
)
158+
def test_yt_ds_attr(ds_xr):
159+
ds = ds_xr.yt.ds()
160+
flds = list(ds_xr.data_vars)
161+
for fld in flds:
162+
assert ("stream", fld) in ds.field_list
163+
164+
f = ds.all_data()[flds[0]]
165+
assert len(f) == ds_xr.data_vars[flds[0]].size

yt_xarray/_utilities.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Tuple
1+
from typing import Optional, Tuple
22

33
import numpy as np
44
import xarray as xr
@@ -20,9 +20,12 @@ def construct_minimal_ds(
2020
z_units: str = "km",
2121
field_name: str = "test_field",
2222
n_fields: int = 1,
23-
coord_order: Tuple[str, str, str] = ["z", "y", "x"],
23+
coord_order: Optional[Tuple[str, str, str]] = None,
2424
) -> xr.Dataset:
2525

26+
if coord_order is None:
27+
coord_order = ("z", "y", "x")
28+
2629
# contruct and return a minimal xarray dataset to use in tests as needed
2730

2831
# current known z types = ["height", "depth", "radius", "altitude"]

0 commit comments

Comments
 (0)