Skip to content

Commit

Permalink
Merge pull request #3870 from neutrinoceros/hotfix_3869
Browse files Browse the repository at this point in the history
BUG: fix a regression where calling annotate_timestamp on a plot from a dataset with code units would crash
  • Loading branch information
matthewturk committed Mar 30, 2022
2 parents d97c3cf + 89940e3 commit 5abe3cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 1 addition & 5 deletions yt/visualization/plot_modifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -2629,11 +2629,7 @@ def __call__(self, plot):
# here the time unit will be in brackets on the annotation.
un = self.time_unit.latex_representation()
time_unit = r"$\ \ (" + un + r")$"
except AttributeError as err:
if plot.ds._uses_code_time_unit:
raise RuntimeError(
"The time unit str repr didn't match expectations, something is wrong."
) from err
except AttributeError:
time_unit = str(self.time_unit).replace("_", " ")
self.text += self.time_format.format(time=float(t), units=time_unit)

Expand Down
9 changes: 9 additions & 0 deletions yt/visualization/tests/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ def test_timestamp_callback():
assert_fname(p.save(prefix)[0])


def test_timestamp_callback_code_units():
# see https://github.com/yt-project/yt/issues/3869
with _cleanup_fname() as prefix:
ds = fake_random_ds(2, unit_system="code")
p = SlicePlot(ds, "z", ("gas", "density"))
p.annotate_timestamp()
assert_fname(p.save(prefix)[0])


def test_scale_callback():
with _cleanup_fname() as prefix:
ax = "z"
Expand Down

0 comments on commit 5abe3cf

Please sign in to comment.