Skip to content
forked from pydata/xarray

Commit

Permalink
Base classes in Python 3 don't need to subclass object (pydata#2950)
Browse files Browse the repository at this point in the history
* Base classes in Python 3 don't need to subclass object

* What's new
  • Loading branch information
crusaderky authored and shoyer committed May 9, 2019
1 parent c04234d commit 24d49fc
Show file tree
Hide file tree
Showing 55 changed files with 114 additions and 112 deletions.
8 changes: 4 additions & 4 deletions asv_bench/benchmarks/dataset_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
os.environ['HDF5_USE_FILE_LOCKING'] = 'FALSE'


class IOSingleNetCDF(object):
class IOSingleNetCDF:
"""
A few examples that benchmark reading/writing a single netCDF file with
xarray
Expand Down Expand Up @@ -214,7 +214,7 @@ def time_load_dataset_scipy_with_time_chunks(self):
chunks=self.time_chunks).load()


class IOMultipleNetCDF(object):
class IOMultipleNetCDF:
"""
A few examples that benchmark reading/writing multiple netCDF files with
xarray
Expand Down Expand Up @@ -419,7 +419,7 @@ def create_delayed_write():
return ds.to_netcdf('file.nc', engine='netcdf4', compute=False)


class IOWriteNetCDFDask(object):
class IOWriteNetCDFDask:
timeout = 60
repeat = 1
number = 5
Expand All @@ -432,7 +432,7 @@ def time_write(self):
self.write.compute()


class IOWriteNetCDFDaskDistributed(object):
class IOWriteNetCDFDaskDistributed:
def setup(self):
try:
import distributed
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}


class Base(object):
class Base:
def setup(self, key):
self.ds = xr.Dataset(
{'var1': (('x', 'y'), randn((nx, ny), frac_nan=0.1)),
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
new_y_long = np.linspace(0.1, 0.9, 1000)


class Interpolation(object):
class Interpolation:
def setup(self, *args, **kwargs):
self.ds = xr.Dataset(
{'var1': (('x', 'y'), randn_xy),
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/reindexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from . import requires_dask


class Reindex(object):
class Reindex:
def setup(self):
data = np.random.RandomState(0).randn(1000, 100, 100)
self.ds = xr.Dataset({'temperature': (('time', 'x', 'y'), data)},
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
randn_long = randn((long_nx, ), frac_nan=0.1)


class Rolling(object):
class Rolling:
def setup(self, *args, **kwargs):
self.ds = xr.Dataset(
{'var1': (('x', 'y'), randn_xy),
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/unstacking.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from . import requires_dask


class Unstacking(object):
class Unstacking:
def setup(self):
data = np.random.RandomState(0).randn(1, 1000, 500)
self.ds = xr.DataArray(data).stack(flat_dim=['dim_1', 'dim_2'])
Expand Down
2 changes: 1 addition & 1 deletion doc/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ typically find tests wrapped in a class.

.. code-block:: python
class TestReallyCoolFeature(object):
class TestReallyCoolFeature:
....
Going forward, we are moving to a more *functional* style using the
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/_code/accessor_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


@xr.register_dataset_accessor('geo')
class GeoAccessor(object):
class GeoAccessor:
def __init__(self, xarray_obj):
self._obj = xarray_obj
self._center = None
Expand Down
4 changes: 3 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ Enhancements
- Character arrays' character dimension name decoding and encoding handled by
``var.encoding['char_dim_name']`` (:issue:`2895`)
By `James McCreight <https://github.com/jmccreight>`_.

- Clean up Python 2 compatibility in code (:issue:`2950`)
By `Guido Imperiale <https://github.com/crusaderky>`_.

Bug fixes
~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def open_dataarray(filename_or_obj, group=None, decode_cf=True,
return data_array


class _MultiFileCloser(object):
class _MultiFileCloser:
def __init__(self, file_objs):
self.file_objs = file_objs

Expand Down
2 changes: 1 addition & 1 deletion xarray/backends/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __exit__(self, exception_type, exception_value, traceback):
self.close()


class ArrayWriter(object):
class ArrayWriter:
def __init__(self, lock=None):
self.sources = []
self.targets = []
Expand Down
4 changes: 2 additions & 2 deletions xarray/backends/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
_DEFAULT_MODE = utils.ReprObject('<unused>')


class FileManager(object):
class FileManager:
"""Manager for acquiring and closing a file object.
Use FileManager subclasses (CachingFileManager in particular) on backend
Expand Down Expand Up @@ -237,7 +237,7 @@ def __repr__(self):
type(self).__name__, self._opener, args_string, self._kwargs)


class _RefCounter(object):
class _RefCounter:
"""Class for keeping track of reference counts."""
def __init__(self, counts):
self._counts = counts
Expand Down
4 changes: 2 additions & 2 deletions xarray/backends/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def acquire(lock, blocking=True):
return lock.acquire(blocking)


class CombinedLock(object):
class CombinedLock:
"""A combination of multiple locks.
Like a locked door, a CombinedLock is locked if any of its constituent
Expand Down Expand Up @@ -167,7 +167,7 @@ def __repr__(self):
return "CombinedLock(%r)" % list(self.locks)


class DummyLock(object):
class DummyLock:
"""DummyLock provides the lock API without any actual locking."""

def acquire(self, blocking=True):
Expand Down
2 changes: 1 addition & 1 deletion xarray/backends/netCDF4_.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _extract_nc4_variable_encoding(variable, raise_on_invalid=False,
return encoding


class GroupWrapper(object):
class GroupWrapper:
"""Wrap netCDF4.Group objects so closing them closes the root group."""
def __init__(self, value):
self.value = value
Expand Down
2 changes: 1 addition & 1 deletion xarray/coding/cftime_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_date_type(calendar):
return calendars[calendar]


class BaseCFTimeOffset(object):
class BaseCFTimeOffset:
_freq = None # type: ClassVar[str]
_day_option = None # type: ClassVar[str]

Expand Down
2 changes: 1 addition & 1 deletion xarray/coding/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SerializationWarning(RuntimeWarning):
"""Warnings about encoding/decoding issues in serialization."""


class VariableCoder(object):
class VariableCoder:
"""Base class for encoding and decoding transformations on variables.
We use coders for transforming variables between xarray's data model and
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _round_field(values, name, freq):
return _round_series(values, name, freq)


class DatetimeAccessor(object):
class DatetimeAccessor:
"""Access datetime fields for DataArrays with datetime-like dtypes.
Similar to pandas, fields can be accessed through the `.dt` attribute
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .utils import not_implemented


class SupportsArithmetic(object):
class SupportsArithmetic:
"""Base class for xarray types that support arithmetic.
Used by Dataset, DataArray, Variable and GroupBy.
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
_JOINS_WITHOUT_FILL_VALUES = frozenset({'inner', 'exact'})


class _UFuncSignature(object):
class _UFuncSignature:
"""Core dimensions signature for a given function.
Based on the signature provided by generalized ufuncs in NumPy.
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _ipython_key_completions_(self):
return self._data._ipython_key_completions_()


class LevelCoordinatesSource(object):
class LevelCoordinatesSource:
"""Iterator for MultiIndex level coordinates.
Used for attribute style lookup with AttrAccessMixin. Not returned directly
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _infer_coords_and_dims(shape, coords, dims):
return new_coords, dims


class _LocIndexer(object):
class _LocIndexer:
def __init__(self, data_array):
self.data_array = data_array

Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def _ipython_key_completions_(self):
if key not in self._dataset._coord_names]


class _LocIndexer(object):
class _LocIndexer:
def __init__(self, dataset):
self.dataset = dataset

Expand Down
4 changes: 2 additions & 2 deletions xarray/core/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@functools.total_ordering
class AlwaysGreaterThan(object):
class AlwaysGreaterThan:
def __gt__(self, other):
return True

Expand All @@ -18,7 +18,7 @@ def __eq__(self, other):


@functools.total_ordering
class AlwaysLessThan(object):
class AlwaysLessThan:
def __lt__(self, other):
return True

Expand Down
4 changes: 2 additions & 2 deletions xarray/core/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AccessorRegistrationWarning(Warning):
"""Warning for conflicts in accessor registration."""


class _CachedAccessor(object):
class _CachedAccessor:
"""Custom property-like object (descriptor) for caching accessors."""

def __init__(self, name, accessor):
Expand Down Expand Up @@ -81,7 +81,7 @@ def register_dataset_accessor(name):
import xarray as xr
@xr.register_dataset_accessor('geo')
class GeoAccessor(object):
class GeoAccessor:
def __init__(self, xarray_obj):
self._obj = xarray_obj
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _inverse_permutation_indices(positions):
return indices


class _DummyGroup(object):
class _DummyGroup:
"""Class for keeping track of grouped dimensions without coordinates.
Should not be user visible.
Expand Down
6 changes: 3 additions & 3 deletions xarray/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def _index_indexer_1d(old_indexer, applied_indexer, size):
return indexer


class ExplicitIndexer(object):
class ExplicitIndexer:
"""Base class for explicit indexer objects.
ExplicitIndexer objects wrap a tuple of values given by their ``tuple``
Expand Down Expand Up @@ -430,7 +430,7 @@ def __init__(self, key):
super(VectorizedIndexer, self).__init__(new_key)


class ExplicitlyIndexed(object):
class ExplicitlyIndexed:
"""Mixin to mark support for Indexer subclasses in indexing."""


Expand Down Expand Up @@ -740,7 +740,7 @@ def _combine_indexers(old_key, shape, new_key):
np.broadcast_arrays(*old_key.tuple)))


class IndexingSupport(object): # could inherit from enum.Enum on Python 3
class IndexingSupport: # could inherit from enum.Enum on Python 3
# for backends that support only basic indexer
BASIC = 'BASIC'
# for backends that support basic / outer indexer
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .variable import Variable, broadcast_variables


class BaseInterpolator(object):
class BaseInterpolator:
'''gerneric interpolator class for normalizing interpolation methods'''
cons_kwargs = {} # type: Dict[str, Any]
call_kwargs = {} # type: Dict[str, Any]
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/nputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _advanced_indexer_subspaces(key):
return mixed_positions, vindex_positions


class NumpyVIndexAdapter(object):
class NumpyVIndexAdapter:
"""Object that implements indexing like vindex on a np.ndarray.
This is a pure Python implementation of (some of) the logic in this NumPy
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _get_keep_attrs(default):
" True, False or 'default'.")


class set_options(object):
class set_options:
"""Set options for xarray in a controlled context.
Currently supported options:
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RESAMPLE_DIM = '__resample_dim__'


class Resample(object):
class Resample:
"""An object that extends the `GroupBy` object with additional logic
for handling specialized re-sampling operations.
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/resample_cftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import pandas as pd


class CFTimeGrouper(object):
class CFTimeGrouper:
"""This is a simple container for the grouping parameters that implements a
single method, the only one required for resampling in xarray. It cannot
be used in a call to groupby like a pandas.Grouper object can."""
Expand Down
4 changes: 2 additions & 2 deletions xarray/core/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .pycompat import dask_array_type


class Rolling(object):
class Rolling:
"""A object that implements the moving window pattern.
See Also
Expand Down Expand Up @@ -435,7 +435,7 @@ def construct(self, window_dim, stride=1, fill_value=dtypes.NA):
**{self.dim: slice(None, None, stride)})


class Coarsen(object):
class Coarsen:
"""A object that implements the coarsen.
See Also
Expand Down
2 changes: 1 addition & 1 deletion xarray/plot/facetgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _nicetitle(coord, value, maxchar, template):
return title


class FacetGrid(object):
class FacetGrid:
"""
Initialize the matplotlib figure and FacetGrid object.
Expand Down
2 changes: 1 addition & 1 deletion xarray/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def hist(darray, figsize=None, size=None, aspect=None, ax=None, **kwargs):

# MUST run before any 2d plotting functions are defined since
# _plot2d decorator adds them as methods here.
class _PlotMethods(object):
class _PlotMethods:
"""
Enables use of xarray.plot functions as attributes on a DataArray.
For example, DataArray.plot.imshow
Expand Down
Loading

0 comments on commit 24d49fc

Please sign in to comment.