Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: deprecate unnecessary functions in the yt.testing namespace, update docs #4439

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/analyzing/filtering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ union into a single ``darkmatter`` field. The ``all`` particle type is a
special case of this.

To create a particle union, you need to import the ``ParticleUnion`` class from
``yt.data_objects.particle_unions``, which you then create and pass into
``yt.data_objects.unions``, which you then create and pass into
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

``add_particle_union`` on a dataset object.

Here is an example, where we union the ``halo`` and ``disk`` particle types
Expand Down
23 changes: 20 additions & 3 deletions doc/source/reference/api/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,10 @@ Cosmology Calculator
Testing Infrastructure
----------------------

The first set of functions are all provided by NumPy.
The core set of testing functions are re-exported from NumPy,
and are deprecated (prefer using
`numpy.testing <https://numpy.org/doc/stable/reference/routines.testing.html>`_
directly).

.. autosummary::

Expand All @@ -839,14 +842,28 @@ The first set of functions are all provided by NumPy.
~yt.testing.assert_allclose
~yt.testing.assert_raises

These are yt-provided functions:
`unyt.testing <https://unyt.readthedocs.io/en/stable/modules/unyt.testing.html>`_
also provides some specialized functions for comparing arrays in a units-aware
fashion.

Finally, yt provides the following functions:

.. autosummary::

~yt.testing.assert_rel_equal
~yt.testing.amrspace
~yt.testing.fake_random_ds
~yt.testing.expand_keywords
~yt.testing.fake_random_ds
~yt.testing.fake_amr_ds
~yt.testing.fake_particle_ds
~yt.testing.fake_tetrahedral_ds
~yt.testing.fake_hexahedral_ds
~yt.testing.small_fake_hexahedral_ds
~yt.testing.fake_stretched_ds
~yt.testing.fake_vr_orientation_test_ds
~yt.testing.fake_sph_orientation_ds
~yt.testing.fake_sph_grid_ds
~yt.testing.fake_octree_ds

These are for the pytest infrastructure:

Expand Down
18 changes: 9 additions & 9 deletions yt/data_objects/tests/test_chunking.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from numpy.testing import assert_equal

from yt.testing import assert_true, fake_random_ds
from yt.testing import fake_random_ds
from yt.units._numpy_wrapper_functions import uconcatenate


Expand Down Expand Up @@ -46,15 +46,15 @@ def test_ds_hold():
ds1 = fake_random_ds(64)
ds2 = fake_random_ds(128)
dd = ds1.all_data()
assert_true(
dd.ds.__hash__() == ds1.__hash__()
) # dd.ds is a weakref, so can't use "is"
assert_true(dd.index is ds1.index)
# dd.ds is a weakref, so can't use "is"
assert dd.ds.__hash__() == ds1.__hash__()

assert dd.index is ds1.index
assert_equal(dd[("index", "ones")].size, 64**3)
with dd._ds_hold(ds2):
assert_true(dd.ds.__hash__() == ds2.__hash__())
assert_true(dd.index is ds2.index)
assert dd.ds.__hash__() == ds2.__hash__()
assert dd.index is ds2.index
assert_equal(dd[("index", "ones")].size, 128**3)
assert_true(dd.ds.__hash__() == ds1.__hash__())
assert_true(dd.index is ds1.index)
assert dd.ds.__hash__() == ds1.__hash__()
assert dd.index is ds1.index
assert_equal(dd[("index", "ones")].size, 64**3)
9 changes: 2 additions & 7 deletions yt/data_objects/tests/test_sph_data_objects.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import numpy as np
from numpy.testing import assert_equal
from numpy.testing import assert_almost_equal, assert_equal

from yt import SlicePlot, add_particle_filter
from yt.loaders import load
from yt.testing import (
assert_almost_equal,
fake_sph_grid_ds,
fake_sph_orientation_ds,
requires_file,
)
from yt.testing import fake_sph_grid_ds, fake_sph_orientation_ds, requires_file


def test_point():
Expand Down
4 changes: 3 additions & 1 deletion yt/frontends/cholla/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from numpy.testing import assert_equal

import yt
from yt.frontends.cholla.api import ChollaDataset
from yt.testing import assert_equal, requires_file, requires_module
from yt.testing import requires_file, requires_module
from yt.utilities.answer_testing.framework import (
data_dir_load,
requires_ds,
Expand Down
9 changes: 3 additions & 6 deletions yt/frontends/chombo/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from numpy.testing import assert_equal

from yt.frontends.chombo.api import ChomboDataset, Orion2Dataset, PlutoDataset
from yt.testing import (
assert_equal,
requires_file,
requires_module,
units_override_check,
)
from yt.testing import requires_file, requires_module, units_override_check
from yt.utilities.answer_testing.framework import (
data_dir_load,
requires_ds,
Expand Down
4 changes: 1 addition & 3 deletions yt/frontends/enzo/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import numpy as np
from numpy.testing import assert_almost_equal, assert_array_equal, assert_equal

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,
requires_file,
requires_module,
units_override_check,
Expand Down
3 changes: 2 additions & 1 deletion yt/frontends/enzo_e/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
from numpy.testing import assert_array_equal, assert_equal

from yt.frontends.enzo_e.api import EnzoEDataset
from yt.frontends.enzo_e.fields import NODAL_FLAGS
from yt.testing import assert_array_equal, assert_equal, requires_file, requires_module
from yt.testing import requires_file, requires_module
from yt.utilities.answer_testing.framework import (
FieldValuesTest,
PixelizedProjectionValuesTest,
Expand Down
4 changes: 3 additions & 1 deletion yt/frontends/exodus_ii/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from yt.testing import assert_array_equal, assert_equal, requires_file
from numpy.testing import assert_array_equal, assert_equal

from yt.testing import requires_file
from yt.utilities.answer_testing.framework import (
GenericArrayTest,
data_dir_load,
Expand Down
9 changes: 3 additions & 6 deletions yt/frontends/fits/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from yt.testing import (
assert_equal,
requires_file,
requires_module,
units_override_check,
)
from numpy.testing import assert_equal

from yt.testing import requires_file, requires_module, units_override_check
from yt.utilities.answer_testing.framework import (
data_dir_load,
requires_ds,
Expand Down
3 changes: 1 addition & 2 deletions yt/frontends/flash/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from collections import OrderedDict

import numpy as np
from numpy.testing import assert_allclose, assert_equal

from yt.frontends.flash.api import FLASHDataset, FLASHParticleDataset
from yt.loaders import load
from yt.testing import (
ParticleSelectionComparison,
assert_allclose,
assert_equal,
disable_dataset_cache,
requires_file,
requires_module,
Expand Down
9 changes: 2 additions & 7 deletions yt/frontends/gadget_fof/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import numpy as np
from numpy.testing import assert_array_equal, assert_equal

from yt.frontends.gadget_fof.api import GadgetFOFDataset
from yt.testing import (
ParticleSelectionComparison,
assert_array_equal,
assert_equal,
requires_file,
requires_module,
)
from yt.testing import ParticleSelectionComparison, requires_file, requires_module
from yt.utilities.answer_testing.framework import (
FieldValuesTest,
data_dir_load,
Expand Down
9 changes: 3 additions & 6 deletions yt/frontends/gamer/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from numpy.testing import assert_array_almost_equal, assert_equal

from yt.frontends.gamer.api import GAMERDataset
from yt.testing import (
assert_array_almost_equal,
assert_equal,
requires_file,
units_override_check,
)
from yt.testing import requires_file, units_override_check
from yt.utilities.answer_testing.framework import (
data_dir_load,
requires_ds,
Expand Down
9 changes: 3 additions & 6 deletions yt/frontends/gdf/tests/test_outputs_nose.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from numpy.testing import assert_equal

from yt.frontends.gdf.api import GDFDataset
from yt.testing import (
assert_equal,
requires_file,
requires_module,
units_override_check,
)
from yt.testing import requires_file, requires_module, units_override_check
from yt.utilities.answer_testing.framework import (
data_dir_load,
requires_ds,
Expand Down
9 changes: 2 additions & 7 deletions yt/frontends/halo_catalog/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import numpy as np
from numpy.testing import assert_array_equal, assert_equal

from yt.frontends.halo_catalog.data_structures import YTHaloCatalogDataset
from yt.frontends.ytdata.utilities import save_as_dataset
from yt.loaders import load as yt_load
from yt.testing import (
TempDirTest,
assert_array_equal,
assert_equal,
requires_file,
requires_module,
)
from yt.testing import TempDirTest, requires_file, requires_module
from yt.units.yt_array import YTArray, YTQuantity
from yt.utilities.answer_testing.framework import data_dir_load

Expand Down
9 changes: 2 additions & 7 deletions yt/frontends/moab/tests/test_c5.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import numpy as np
from numpy.testing import assert_almost_equal, assert_equal

from yt.frontends.moab.api import MoabHex8Dataset
from yt.testing import (
assert_almost_equal,
assert_equal,
requires_file,
requires_module,
units_override_check,
)
from yt.testing import requires_file, requires_module, units_override_check
from yt.utilities.answer_testing.framework import (
FieldValuesTest,
data_dir_load,
Expand Down
4 changes: 3 additions & 1 deletion yt/frontends/nc4_cm1/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from numpy.testing import assert_equal

from yt.frontends.nc4_cm1.api import CM1Dataset
from yt.testing import assert_equal, requires_file, units_override_check
from yt.testing import requires_file, units_override_check
from yt.utilities.answer_testing.framework import (
FieldValuesTest,
GridValuesTest,
Expand Down
9 changes: 2 additions & 7 deletions yt/frontends/open_pmd/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
from itertools import product

import numpy as np
from numpy.testing import assert_almost_equal, assert_array_equal, assert_equal

from yt.frontends.open_pmd.data_structures import OpenPMDDataset
from yt.loaders import load
from yt.testing import (
assert_almost_equal,
assert_array_equal,
assert_equal,
requires_file,
requires_module,
)
from yt.testing import requires_file, requires_module
from yt.utilities.answer_testing.framework import data_dir_load

twoD = "example-2d/hdf5/data00000100.h5"
Expand Down
4 changes: 3 additions & 1 deletion yt/frontends/owls_subfind/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os.path

from yt.testing import assert_equal, requires_module
from numpy.testing import assert_equal

from yt.testing import requires_module
from yt.utilities.answer_testing.framework import (
FieldValuesTest,
data_dir_load,
Expand Down
9 changes: 2 additions & 7 deletions yt/frontends/ramses/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import os

import numpy as np
from numpy.testing import assert_equal, assert_raises

import yt
from yt.config import ytcfg
from yt.fields.field_detector import FieldDetector
from yt.frontends.ramses.api import RAMSESDataset
from yt.frontends.ramses.field_handlers import DETECTED_FIELDS, HydroFieldFileHandler
from yt.testing import (
assert_equal,
assert_raises,
requires_file,
requires_module,
units_override_check,
)
from yt.testing import requires_file, requires_module, units_override_check
from yt.utilities.answer_testing.framework import (
FieldValuesTest,
PixelizedProjectionValuesTest,
Expand Down
4 changes: 3 additions & 1 deletion yt/frontends/rockstar/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os.path

from numpy.testing import assert_equal

from yt.frontends.rockstar.api import RockstarDataset
from yt.testing import ParticleSelectionComparison, assert_equal, requires_file
from yt.testing import ParticleSelectionComparison, requires_file
from yt.utilities.answer_testing.framework import (
FieldValuesTest,
data_dir_load,
Expand Down
8 changes: 2 additions & 6 deletions yt/frontends/swift/tests/test_outputs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import numpy as np
from numpy.testing import assert_almost_equal

from yt import load
from yt.frontends.swift.api import SwiftDataset
from yt.testing import (
ParticleSelectionComparison,
assert_almost_equal,
requires_file,
requires_module,
)
from yt.testing import ParticleSelectionComparison, requires_file, requires_module
from yt.utilities.on_demand_imports import _h5py as h5py

keplerian_ring = "KeplerianRing/keplerian_ring_0020.hdf5"
Expand Down
2 changes: 1 addition & 1 deletion yt/frontends/ytdata/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import tempfile

import numpy as np
from numpy.testing import assert_array_equal

from yt.loaders import load, load_uniform_grid
from yt.testing import (
assert_array_equal,
assert_fname,
fake_random_ds,
requires_file,
Expand Down
3 changes: 2 additions & 1 deletion yt/geometry/coordinates/tests/test_spherical_coordinates.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Some tests for the Spherical coordinates handler

import numpy as np
from numpy.testing import assert_almost_equal, assert_equal

from yt.testing import assert_almost_equal, assert_equal, fake_amr_ds
from yt.testing import fake_amr_ds

# Our canonical tests are that we can access all of our fields and we can
# compute our volume correctly.
Expand Down
4 changes: 2 additions & 2 deletions yt/geometry/tests/test_particle_octree.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from yt.geometry.oct_container import _ORDER_MAX
from yt.geometry.particle_oct_container import ParticleBitmap, ParticleOctreeContainer
from yt.geometry.selection_routines import RegionSelector
from yt.testing import assert_true, requires_module
from yt.testing import requires_module
from yt.units.unit_registry import UnitRegistry
from yt.units.yt_array import YTArray
from yt.utilities.lib.geometry_utils import (
Expand Down Expand Up @@ -302,7 +302,7 @@ def test_bitmap_save_load():
left_edge, right_edge, periodicity, file_hash, nfiles, order1, order2
)
reg1.load_bitmasks(fname)
assert_true(reg0.iseq_bitmask(reg1))
assert reg0.iseq_bitmask(reg1)
# Remove file
os.remove(fname)

Expand Down
Loading