Skip to content

Commit

Permalink
DEPR: deprecate yt.testing.assert_allclose_units in favour of equival…
Browse files Browse the repository at this point in the history
…ent function in unyt.testing
  • Loading branch information
neutrinoceros committed May 6, 2023
1 parent 7866b06 commit 1aa3bf5
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 83 deletions.
3 changes: 2 additions & 1 deletion yt/data_objects/tests/test_bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import numpy as np
from numpy.testing import assert_equal
from unyt.testing import assert_allclose_units

from yt.testing import assert_allclose_units, fake_amr_ds
from yt.testing import fake_amr_ds


def test_object_bbox():
Expand Down
3 changes: 2 additions & 1 deletion yt/fields/tests/test_angular_momentum.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
from unyt.testing import assert_allclose_units

from yt.testing import assert_allclose_units, fake_amr_ds
from yt.testing import fake_amr_ds


def test_AM_value():
Expand Down
2 changes: 1 addition & 1 deletion yt/fields/tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
assert_equal,
assert_raises,
)
from unyt.testing import assert_allclose_units

from yt import load
from yt.frontends.stream.fields import StreamFieldInfo
from yt.testing import (
assert_allclose_units,
fake_amr_ds,
fake_particle_ds,
fake_random_ds,
Expand Down
4 changes: 3 additions & 1 deletion yt/fields/tests/test_particle_fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from yt.testing import assert_allclose_units, requires_file, requires_module
from unyt.testing import assert_allclose_units

from yt.testing import requires_file, requires_module
from yt.utilities.answer_testing.framework import data_dir_load

g30 = "IsolatedGalaxy/galaxy0030/galaxy0030"
Expand Down
3 changes: 2 additions & 1 deletion yt/fields/tests/test_species_fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from numpy.testing import assert_equal
from unyt.testing import assert_allclose_units

from yt.testing import assert_allclose_units, fake_random_ds
from yt.testing import fake_random_ds
from yt.utilities.chemical_formulas import ChemicalFormula
from yt.utilities.physical_ratios import _primordial_mass_fraction

Expand Down
8 changes: 2 additions & 6 deletions yt/fields/tests/test_vector_fields.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import numpy as np
from unyt.testing import assert_allclose_units

from yt.testing import (
assert_allclose_units,
fake_random_ds,
requires_file,
requires_module,
)
from yt.testing import fake_random_ds, requires_file, requires_module
from yt.units import cm, s # type: ignore
from yt.utilities.answer_testing.framework import data_dir_load
from yt.visualization.volume_rendering.off_axis_projection import off_axis_projection
Expand Down
3 changes: 2 additions & 1 deletion yt/frontends/amrvac/tests/test_units_override.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from numpy.testing import assert_raises
from unyt.testing import assert_allclose_units

from yt.testing import assert_allclose_units, requires_file
from yt.testing import requires_file
from yt.units import YTQuantity
from yt.utilities.answer_testing.framework import data_dir_load

Expand Down
3 changes: 2 additions & 1 deletion yt/frontends/arepo/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from collections import OrderedDict

from unyt.testing import assert_allclose_units

from yt.frontends.arepo.api import ArepoHDF5Dataset
from yt.testing import (
ParticleSelectionComparison,
assert_allclose_units,
requires_file,
requires_module,
)
Expand Down
2 changes: 1 addition & 1 deletion yt/frontends/artio/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from numpy.testing import assert_equal
from unyt.testing import assert_allclose_units

from yt.frontends.artio.api import ARTIODataset
from yt.loaders import load
from yt.testing import (
assert_allclose_units,
requires_file,
units_override_check,
)
Expand Down
7 changes: 2 additions & 5 deletions yt/frontends/athena/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import numpy as np
from numpy.testing import assert_equal
from unyt.testing import assert_allclose_units

from yt.frontends.athena.api import AthenaDataset
from yt.loaders import load
from yt.testing import (
assert_allclose_units,
disable_dataset_cache,
requires_file,
)
from yt.testing import disable_dataset_cache, requires_file
from yt.utilities.answer_testing.framework import (
data_dir_load,
requires_ds,
Expand Down
8 changes: 2 additions & 6 deletions yt/frontends/athena_pp/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import numpy as np
from numpy.testing import assert_equal
from unyt.testing import assert_allclose_units

from yt.frontends.athena_pp.api import AthenaPPDataset
from yt.loaders import load
from yt.testing import (
assert_allclose_units,
disable_dataset_cache,
requires_file,
units_override_check,
)
from yt.testing import disable_dataset_cache, requires_file, units_override_check
from yt.units import dimensions
from yt.utilities.answer_testing.framework import (
data_dir_load,
Expand Down
2 changes: 1 addition & 1 deletion yt/frontends/enzo/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import numpy as np
from unyt.testing import assert_allclose_units

from yt.frontends.enzo.api import EnzoDataset
from yt.frontends.enzo.fields import NODAL_FLAGS
from yt.testing import (
assert_allclose_units,
assert_almost_equal,
assert_array_equal,
assert_equal,
Expand Down
9 changes: 2 additions & 7 deletions yt/frontends/ytdata/tests/test_old_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import tempfile

import numpy as np
from unyt.testing import assert_allclose_units

from yt.data_objects.api import create_profile
from yt.frontends.ytdata.api import (
Expand All @@ -23,13 +24,7 @@
YTDataFieldTest,
compare_unit_attributes,
)
from yt.testing import (
assert_allclose_units,
assert_array_equal,
requires_file,
requires_module,
skip,
)
from yt.testing import assert_array_equal, requires_file, requires_module, skip
from yt.units.yt_array import YTArray
from yt.utilities.answer_testing.framework import data_dir_load, requires_ds
from yt.visualization.profile_plotter import PhasePlot, ProfilePlot
Expand Down
2 changes: 1 addition & 1 deletion yt/frontends/ytdata/tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
from numpy.testing import assert_array_equal, assert_equal
from unyt.testing import assert_allclose_units

from yt.data_objects.api import create_profile
from yt.frontends.ytdata.api import (
Expand All @@ -15,7 +16,6 @@
save_as_dataset,
)
from yt.loaders import load
from yt.testing import assert_allclose_units
from yt.units.yt_array import YTArray, YTQuantity
from yt.utilities.answer_testing.framework import (
AnswerTestingTest,
Expand Down
4 changes: 3 additions & 1 deletion yt/geometry/tests/test_grid_index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from yt.testing import assert_allclose_units, fake_amr_ds
from unyt.testing import assert_allclose_units

from yt.testing import fake_amr_ds


def test_icoords_to_ires():
Expand Down
47 changes: 9 additions & 38 deletions yt/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
import pytest
from more_itertools import always_iterable
from numpy.random import RandomState
from unyt.exceptions import UnitOperationError

from yt._maintenance.deprecation import issue_deprecation_warning
from yt.config import ytcfg
from yt.funcs import is_sequence
from yt.loaders import load
from yt.units.yt_array import YTArray, YTQuantity

ANSWER_TEST_TAG = "answer_test"

Expand Down Expand Up @@ -1261,43 +1259,16 @@ def assert_allclose_units(actual, desired, rtol=1e-7, atol=0, **kwargs):
function for details.
"""
from numpy.testing import assert_allclose
from unyt.testing import assert_allclose_units

# Create a copy to ensure this function does not alter input arrays
act = YTArray(actual)
des = YTArray(desired)

try:
des = des.in_units(act.units)
except UnitOperationError as e:
raise AssertionError(
f"Units of actual ({act.units}) and desired ({des.units}) "
"do not have equivalent dimensions"
) from e

rt = YTArray(rtol)
if not rt.units.is_dimensionless:
raise AssertionError(f"Units of rtol ({rt.units}) are not dimensionless")

if not isinstance(atol, YTArray):
at = YTQuantity(atol, des.units)

try:
at = at.in_units(act.units)
except UnitOperationError as e:
raise AssertionError(
f"Units of atol ({at.units}) and actual ({act.units}) "
"do not have equivalent dimensions"
) from e

# units have been validated, so we strip units before calling numpy
# to avoid spurious errors
act = act.value
des = des.value
rt = rt.value
at = at.value

return assert_allclose(act, des, rt, at, **kwargs)
issue_deprecation_warning(
"yt.testing.assert_allclose_units is a deprecated alias for "
"unyt.testing.assert_allclose_units. "
"Please use the function from unyt directly.",
since="4.2",
stacklevel=2,
)
assert_allclose_units(actual, desired, rtol=rtol, atol=atol, **kwargs)


def assert_fname(fname):
Expand Down
9 changes: 2 additions & 7 deletions yt/utilities/answer_testing/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,13 @@
from matplotlib import image as mpimg
from matplotlib.testing.compare import compare_images
from nose.plugins import Plugin
from unyt.testing import assert_allclose_units

from yt.config import ytcfg
from yt.data_objects.static_output import Dataset
from yt.funcs import get_pbar, get_yt_version
from yt.loaders import load, load_simulation
from yt.testing import (
assert_allclose_units,
assert_almost_equal,
assert_equal,
assert_rel_equal,
skipif,
)
from yt.testing import assert_almost_equal, assert_equal, assert_rel_equal, skipif
from yt.utilities.exceptions import (
YTAmbiguousDataType,
YTCloudError,
Expand Down
3 changes: 2 additions & 1 deletion yt/visualization/tests/test_export_frb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
from numpy.testing import assert_equal
from unyt.testing import assert_allclose_units

from yt.testing import assert_allclose_units, fake_random_ds
from yt.testing import fake_random_ds


def setup():
Expand Down
2 changes: 1 addition & 1 deletion yt/visualization/tests/test_plotwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
assert_raises,
)
from unyt import unyt_array
from unyt.testing import assert_allclose_units

from yt.loaders import load_uniform_grid
from yt.testing import (
assert_allclose_units,
assert_fname,
assert_rel_equal,
fake_amr_ds,
Expand Down
3 changes: 2 additions & 1 deletion yt/visualization/tests/test_profile_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import unittest

import pytest
from unyt.testing import assert_allclose_units

import yt
from yt.testing import assert_allclose_units, fake_random_ds
from yt.testing import fake_random_ds
from yt.visualization.api import PhasePlot


Expand Down

0 comments on commit 1aa3bf5

Please sign in to comment.