Skip to content

Commit 8afa1ef

Browse files
committed
Allow passing (value, 'units') to compare fields
1 parent 9519d0d commit 8afa1ef

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

yt/fields/derived_field.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,15 @@ def wrapped(field, data):
517517
other_units = self.ds.get_unit_from_registry(other.units)
518518

519519
else:
520+
# Special case when passing (value, "unit") tuple
521+
if isinstance(other, tuple) and len(other) == 2:
522+
other = self.ds.quan(*other)
520523

521524
def wrapped(field, data):
522525
return op(self(data), other)
523526

524527
other_name = str(other)
525-
other_units = self.ds.get_unit_from_registry(getattr(other, "units", "1"))
528+
other_units = getattr(other, "units", self.ds.get_unit_from_registry("1"))
526529

527530
if op in (operator.add, operator.sub, operator.eq):
528531
assert my_units.same_dimensions_as(other_units)

0 commit comments

Comments
 (0)