Skip to content

Commit b4cc03c

Browse files
authored
Merge pull request #5000 from chrishavlin/ensure_slice_coord_has_units
BUG: ensure YTSlice.coord has units
2 parents aadfcaa + 16c4283 commit b4cc03c

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

yt/data_objects/selection_objects/slices.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
)
77
from yt.data_objects.static_output import Dataset
88
from yt.funcs import (
9+
fix_length,
910
is_sequence,
1011
iter_fields,
1112
validate_3d_array,
@@ -78,7 +79,7 @@ def __init__(
7879
validate_object(data_source, YTSelectionContainer)
7980
YTSelectionContainer2D.__init__(self, axis, ds, field_parameters, data_source)
8081
self._set_center(center)
81-
self.coord = coord
82+
self.coord = fix_length(coord, ds)
8283

8384
def _generate_container_field(self, field):
8485
xax = self.ds.coordinates.x_axis[self.axis]

yt/data_objects/tests/test_sph_data_objects.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ def test_slice():
6464
}
6565

6666

67+
def test_slice_to_frb():
68+
ds = fake_sph_orientation_ds()
69+
frb = ds.slice(0, 0.5).to_frb(ds.domain_width[0], (64, 64))
70+
ref_vals = frb["gas", "density"]
71+
for center in ((0.5, "code_length"), (0.5, "cm"), ds.quan(0.5, "code_length")):
72+
frb = ds.slice(0, center).to_frb(ds.domain_width[0], (64, 64))
73+
vals = frb["gas", "density"]
74+
assert_equal(vals, ref_vals)
75+
76+
6777
def test_region():
6878
ds = fake_sph_orientation_ds()
6979
for (left_edge, right_edge), answer in REGION_ANSWERS.items():

yt/funcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ def validate_3d_array(obj):
11061106
def validate_float(obj):
11071107
"""Validates if the passed argument is a float value.
11081108
1109-
Raises an exception if `obj` is a single float value
1109+
Raises an exception if `obj` is not a single float value
11101110
or a YTQuantity of size 1.
11111111
11121112
Parameters

0 commit comments

Comments
 (0)