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

RFC: simplify/clarify inheritance hierarchy for yt.data_objects.unions.Union #4210

Merged
merged 1 commit into from
Nov 19, 2022
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
13 changes: 7 additions & 6 deletions yt/data_objects/particle_unions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from .unions import Union
from yt._maintenance.deprecation import issue_deprecation_warning

from .unions import ParticleUnion # noqa: F401

class ParticleUnion(Union):
_union_type = "particle"

def __init__(self, name, sub_types):
super().__init__(name, sub_types)
issue_deprecation_warning(
"Importing ParticleUnion from yt.data_objects.particle_unions is deprecated. "
"Please import this class from yt.data_objects.unions instead",
since="4.2",
)
2 changes: 1 addition & 1 deletion yt/data_objects/static_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from yt._maintenance.deprecation import issue_deprecation_warning
from yt.config import ytcfg
from yt.data_objects.particle_filters import filter_registry
from yt.data_objects.particle_unions import ParticleUnion
from yt.data_objects.region_expression import RegionExpression
from yt.data_objects.unions import ParticleUnion
from yt.fields.derived_field import ValidateSpatial
from yt.fields.field_type_container import FieldTypeContainer
from yt.fields.fluid_fields import setup_gradient_fields
Expand Down
14 changes: 10 additions & 4 deletions yt/data_objects/unions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from abc import ABC, abstractmethod

from more_itertools import always_iterable


class Union:
_union_type = ""
class Union(ABC):
@property
@abstractmethod
def _union_type(self) -> str:
...

def __init__(self, name, sub_types):
self.name = name
Expand All @@ -20,5 +25,6 @@ def __repr__(self):
class MeshUnion(Union):
_union_type = "mesh"

def __init__(self, name, sub_types):
super().__init__(name, sub_types)

class ParticleUnion(Union):
_union_type = "particle"
2 changes: 1 addition & 1 deletion yt/frontends/art/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import yt.utilities.fortran_utils as fpu
from yt.data_objects.index_subobjects.octree_subset import OctreeSubset
from yt.data_objects.particle_unions import ParticleUnion
from yt.data_objects.static_output import Dataset, ParticleFile
from yt.data_objects.unions import ParticleUnion
from yt.frontends.art.definitions import (
amr_header_struct,
constants,
Expand Down
2 changes: 1 addition & 1 deletion yt/frontends/artio/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from yt.data_objects.field_data import YTFieldData
from yt.data_objects.index_subobjects.octree_subset import OctreeSubset
from yt.data_objects.particle_unions import ParticleUnion
from yt.data_objects.static_output import Dataset
from yt.data_objects.unions import ParticleUnion
from yt.frontends.artio import _artio_caller
from yt.frontends.artio._artio_caller import (
ARTIOSFCRangeHandler,
Expand Down
3 changes: 1 addition & 2 deletions yt/frontends/stream/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
SemiStructuredMesh,
UnstructuredMesh,
)
from yt.data_objects.particle_unions import ParticleUnion
from yt.data_objects.static_output import Dataset, ParticleFile
from yt.data_objects.unions import MeshUnion
from yt.data_objects.unions import MeshUnion, ParticleUnion
from yt.frontends.sph.data_structures import SPHParticleIndex
from yt.funcs import setdefaultattr
from yt.geometry.geometry_handler import Index, YTDataChunk
Expand Down
2 changes: 1 addition & 1 deletion yt/frontends/ytdata/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import numpy as np

from yt.data_objects.index_subobjects.grid_patch import AMRGridPatch
from yt.data_objects.particle_unions import ParticleUnion
from yt.data_objects.profiles import (
Profile1DFromDataset,
Profile2DFromDataset,
Profile3DFromDataset,
)
from yt.data_objects.static_output import Dataset, ParticleFile, validate_index_order
from yt.data_objects.unions import ParticleUnion
from yt.fields.field_exceptions import NeedsGridType
from yt.fields.field_info_container import FieldInfoContainer
from yt.funcs import is_root, parse_h5_attr
Expand Down