Skip to content

Commit

Permalink
Apply ruff rule RUF023
Browse files Browse the repository at this point in the history
RUF023 `__slots__` is not sorted
  • Loading branch information
DimitriPapadopoulos committed Nov 6, 2024
1 parent c4ccc20 commit 35439d1
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion xarray/backends/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def __exit__(self, exception_type, exception_value, traceback):


class ArrayWriter:
__slots__ = ("sources", "targets", "regions", "lock")
__slots__ = ("lock", "regions", "sources", "targets")

def __init__(self, lock=None):
self.sources = []
Expand Down
8 changes: 4 additions & 4 deletions xarray/backends/h5netcdf_.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ class H5NetCDFStore(WritableCFDataStore):
"""Store for reading and writing data via h5netcdf"""

__slots__ = (
"autoclose",
"format",
"is_remote",
"lock",
"_filename",
"_group",
"_manager",
"_mode",
"autoclose",
"format",
"is_remote",
"lock",
)

def __init__(self, manager, group=None, mode=None, lock=HDF5_LOCK, autoclose=False):
Expand Down
8 changes: 4 additions & 4 deletions xarray/backends/netCDF4_.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,14 @@ class NetCDF4DataStore(WritableCFDataStore):
"""

__slots__ = (
"autoclose",
"format",
"is_remote",
"lock",
"_filename",
"_group",
"_manager",
"_mode",
"autoclose",
"format",
"is_remote",
"lock",
)

def __init__(
Expand Down
12 changes: 6 additions & 6 deletions xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def encode_zarr_attr_value(value):


class ZarrArrayWrapper(BackendArray):
__slots__ = ("dtype", "shape", "_array")
__slots__ = ("_array", "dtype", "shape")

def __init__(self, zarr_array):
# some callers attempt to evaluate an array if an `array` property exists on the object.
Expand Down Expand Up @@ -598,18 +598,18 @@ class ZarrStore(AbstractWritableDataStore):
"""Store for reading and writing data via zarr"""

__slots__ = (
"zarr_group",
"_append_dim",
"_close_store_on_close",
"_consolidate_on_close",
"_group",
"_mode",
"_read_only",
"_synchronizer",
"_write_region",
"_safe_chunks",
"_write_empty",
"_close_store_on_close",
"_synchronizer",
"_use_zarr_fill_value_as_mask",
"_write_empty",
"_write_region",
"zarr_group",
)

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ class _UFuncSignature:
"""

__slots__ = (
"input_core_dims",
"output_core_dims",
"_all_core_dims",
"_all_input_core_dims",
"_all_output_core_dims",
"_all_core_dims",
"input_core_dims",
"output_core_dims",
)

def __init__(self, input_core_dims, output_core_dims=((),)):
Expand Down
4 changes: 2 additions & 2 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,13 @@ class DataArray(
_variable: Variable

__slots__ = (
"__weakref__",
"_cache",
"_coords",
"_close",
"_coords",
"_indexes",
"_name",
"_variable",
"__weakref__",
)

dt = utils.UncachedAccessor(CombinedDatetimelikeAccessor["DataArray"])
Expand Down
4 changes: 2 additions & 2 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,15 +684,15 @@ class Dataset(
_variables: dict[Hashable, Variable]

__slots__ = (
"__weakref__",
"_attrs",
"_cache",
"_close",
"_coord_names",
"_dims",
"_encoding",
"_close",
"_indexes",
"_variables",
"__weakref__",
)

def __init__(
Expand Down
14 changes: 7 additions & 7 deletions xarray/core/datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ class DatasetView(Dataset):
__slots__ = (
"_attrs",
"_cache", # used by _CachedAccessor
"_close",
"_coord_names",
"_dims",
"_encoding",
"_close",
"_indexes",
"_variables",
)
Expand Down Expand Up @@ -457,17 +457,17 @@ class DataTree(
_close: Callable[[], None] | None

__slots__ = (
"_name",
"_parent",
"_children",
"_attrs",
"_cache", # used by _CachedAccessor
"_children",
"_close",
"_data_variables",
"_encoding",
"_name",
"_node_coord_variables",
"_node_dims",
"_node_indexes",
"_attrs",
"_encoding",
"_close",
"_parent",
)

def __init__(
Expand Down
22 changes: 11 additions & 11 deletions xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class _DummyGroup(Generic[T_Xarray]):
Should not be user visible.
"""

__slots__ = ("name", "coords", "size", "dataarray")
__slots__ = ("coords", "dataarray", "name", "size")

def __init__(self, obj: T_Xarray, name: Hashable, coords) -> None:
self.name = name
Expand Down Expand Up @@ -567,24 +567,24 @@ class GroupBy(Generic[T_Xarray]):
"""

__slots__ = (
"_by_chunked",
"_codes",
"_dims",
"_group_dim",
"groupers",
"_obj",
"_restore_coord_dims",
# cached properties
"_groups",
"_dims",
"_sizes",
"_inserted_dims",
"_len",
"_by_chunked",
"_obj",
# Save unstacked object for flox
"_original_obj",
"_codes",
# stack nD vars
"group1d",
"_restore_coord_dims",
"_sizes",
"_stacked_dim",
"_inserted_dims",
"encoded",
# stack nD vars
"group1d",
"groupers",
)
_obj: T_Xarray
groupers: tuple[ResolvedGrouper, ...]
Expand Down
12 changes: 6 additions & 6 deletions xarray/core/indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ class PandasIndex(Index):
dim: Hashable
coord_dtype: Any

__slots__ = ("index", "dim", "coord_dtype")
__slots__ = ("coord_dtype", "dim", "index")

def __init__(
self,
Expand Down Expand Up @@ -939,7 +939,7 @@ class PandasMultiIndex(PandasIndex):
coord_dtype: Any
level_coords_dtype: dict[str, Any]

__slots__ = ("index", "dim", "coord_dtype", "level_coords_dtype")
__slots__ = ("coord_dtype", "dim", "index", "level_coords_dtype")

def __init__(self, array: Any, dim: Hashable, level_coords_dtype: Any = None):
super().__init__(array, dim)
Expand Down Expand Up @@ -1451,13 +1451,13 @@ class Indexes(collections.abc.Mapping, Generic[T_PandasOrXarrayIndex]):
_variables: dict[Any, Variable]

__slots__ = (
"__coord_name_id",
"__id_coord_names",
"__id_index",
"_dims",
"_index_type",
"_indexes",
"_variables",
"_dims",
"__coord_name_id",
"__id_index",
"__id_coord_names",
)

def __init__(
Expand Down
8 changes: 4 additions & 4 deletions xarray/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def __getitem__(self, key: Any):
class LazilyIndexedArray(ExplicitlyIndexedNDArrayMixin):
"""Wrap an array to make basic and outer indexing lazy."""

__slots__ = ("array", "key", "_shape")
__slots__ = ("_shape", "array", "key")

def __init__(self, array: Any, key: ExplicitIndexer | None = None):
"""
Expand Down Expand Up @@ -779,7 +779,7 @@ def _wrap_numpy_scalars(array):


class CopyOnWriteArray(ExplicitlyIndexedNDArrayMixin):
__slots__ = ("array", "_copied")
__slots__ = ("_copied", "array")

def __init__(self, array: duckarray[Any, Any]):
self.array = as_indexable(array)
Expand Down Expand Up @@ -1658,7 +1658,7 @@ def transpose(self, order):
class PandasIndexingAdapter(ExplicitlyIndexedNDArrayMixin):
"""Wrap a pandas.Index to preserve dtypes and handle explicit indexing."""

__slots__ = ("array", "_dtype")
__slots__ = ("_dtype", "array")

array: pd.Index
_dtype: np.dtype
Expand Down Expand Up @@ -1825,7 +1825,7 @@ class PandasMultiIndexingAdapter(PandasIndexingAdapter):
the same multi-index).
"""

__slots__ = ("array", "_dtype", "level", "adapter")
__slots__ = ("_dtype", "adapter", "array", "level")

array: pd.MultiIndex
_dtype: np.dtype
Expand Down
6 changes: 3 additions & 3 deletions xarray/core/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Rolling(Generic[T_Xarray]):
xarray.DataArray.rolling
"""

__slots__ = ("obj", "window", "min_periods", "center", "dim")
__slots__ = ("center", "dim", "min_periods", "obj", "window")
_attributes = ("window", "min_periods", "center", "dim")
dim: list[Hashable]
window: list[int]
Expand Down Expand Up @@ -907,12 +907,12 @@ class Coarsen(CoarsenArithmetic, Generic[T_Xarray]):
"""

__slots__ = (
"obj",
"boundary",
"coord_func",
"windows",
"obj",
"side",
"trim_excess",
"windows",
)
_attributes = ("windows", "side", "trim_excess")
obj: T_Xarray
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class Variable(NamedArray, AbstractArray, VariableArithmetic):
they can use more complete metadata in context of coordinate labels.
"""

__slots__ = ("_dims", "_data", "_attrs", "_encoding")
__slots__ = ("_attrs", "_data", "_dims", "_encoding")

def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion xarray/namedarray/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class NamedArray(NamedArrayAggregations, Generic[_ShapeType_co, _DType_co]):
>>> narr = NamedArray(("x",), data, {"units": "m"}) # TODO: Better name than narr?
"""

__slots__ = ("_data", "_dims", "_attrs")
__slots__ = ("_attrs", "_data", "_dims")

_data: duckarray[Any, _DType_co]
_dims: _Dims
Expand Down
2 changes: 1 addition & 1 deletion xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,10 +1383,10 @@ class _Normalize(Sequence):

__slots__ = (
"_data",
"_data_is_numeric",
"_data_unique",
"_data_unique_index",
"_data_unique_inverse",
"_data_is_numeric",
"_width",
)

Expand Down

0 comments on commit 35439d1

Please sign in to comment.