Skip to content

Commit

Permalink
Cleanup uses of super() to use Python 3 only syntax (#3069)
Browse files Browse the repository at this point in the history
No user facing changes
  • Loading branch information
shoyer committed Jul 2, 2019
1 parent 8c61997 commit 378c330
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/indexing.py
Expand Up @@ -122,5 +122,5 @@ def time_assignment_vectorized(self, key):
class IndexingDask(Indexing):
def setup(self, key):
requires_dask()
super(IndexingDask, self).setup(key)
super().setup(key)
self.ds = self.ds.chunk({'x': 100, 'y': 50, 't': 50})
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/interp.py
Expand Up @@ -50,5 +50,5 @@ def time_interpolation_2d(self, method):
class InterpolationDask(Interpolation):
def setup(self, *args, **kwargs):
requires_dask()
super(InterpolationDask, self).setup(**kwargs)
super().setup(**kwargs)
self.ds = self.ds.chunk({'t': 50})
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/reindexing.py
Expand Up @@ -40,5 +40,5 @@ def time_2d_fine_some_missing(self):
class ReindexDask(Reindex):
def setup(self):
requires_dask()
super(ReindexDask, self).setup()
super().setup()
self.ds = self.ds.chunk({'time': 100})
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/rolling.py
Expand Up @@ -63,6 +63,6 @@ def time_rolling_construct(self, center, stride):
class RollingDask(Rolling):
def setup(self, *args, **kwargs):
requires_dask()
super(RollingDask, self).setup(**kwargs)
super().setup(**kwargs)
self.ds = self.ds.chunk({'x': 100, 'y': 50, 't': 50})
self.da_long = self.da_long.chunk({'x': 10000})
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/unstacking.py
Expand Up @@ -22,5 +22,5 @@ def time_unstack_slow(self):
class UnstackingDask(Unstacking):
def setup(self, *args, **kwargs):
requires_dask()
super(UnstackingDask, self).setup(**kwargs)
super().setup(**kwargs)
self.ds = self.ds.chunk({'flat_dim': 50})
6 changes: 3 additions & 3 deletions xarray/core/indexing.py
Expand Up @@ -352,7 +352,7 @@ def __init__(self, key):
.format(type(self).__name__, k))
new_key.append(k)

super(BasicIndexer, self).__init__(new_key)
super().__init__(new_key)


class OuterIndexer(ExplicitIndexer):
Expand Down Expand Up @@ -388,7 +388,7 @@ def __init__(self, key):
.format(type(self).__name__, k))
new_key.append(k)

super(OuterIndexer, self).__init__(new_key)
super().__init__(new_key)


class VectorizedIndexer(ExplicitIndexer):
Expand Down Expand Up @@ -427,7 +427,7 @@ def __init__(self, key):
.format(type(self).__name__, k))
new_key.append(k)

super(VectorizedIndexer, self).__init__(new_key)
super().__init__(new_key)


class ExplicitlyIndexed:
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/merge.py
Expand Up @@ -110,7 +110,7 @@ class OrderedDefaultDict(OrderedDict):
# beware: does not pickle or copy properly
def __init__(self, default_factory):
self.default_factory = default_factory
super(OrderedDefaultDict, self).__init__()
super().__init__()

def __missing__(self, key):
self[key] = default = self.default_factory()
Expand Down
8 changes: 4 additions & 4 deletions xarray/core/resample.py
Expand Up @@ -163,7 +163,7 @@ def __init__(self, *args, dim=None, resample_dim=None, **kwargs):
self._dim = dim
self._resample_dim = resample_dim

super(DataArrayResample, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def apply(self, func, shortcut=False, args=(), **kwargs):
"""Apply a function over each array in the group and concatenate them
Expand Down Expand Up @@ -204,7 +204,7 @@ def apply(self, func, shortcut=False, args=(), **kwargs):
applied : DataArray or DataArray
The result of splitting, applying and combining this array.
"""
combined = super(DataArrayResample, self).apply(
combined = super().apply(
func, shortcut=shortcut, args=args, **kwargs)

# If the aggregation function didn't drop the original resampling
Expand Down Expand Up @@ -236,7 +236,7 @@ def __init__(self, *args, dim=None, resample_dim=None, **kwargs):
self._dim = dim
self._resample_dim = resample_dim

super(DatasetResample, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def apply(self, func, args=(), shortcut=None, **kwargs):
"""Apply a function over each Dataset in the groups generated for
Expand Down Expand Up @@ -301,7 +301,7 @@ def reduce(self, func, dim=None, keep_attrs=None, **kwargs):
if dim == DEFAULT_DIMS:
dim = None

return super(DatasetResample, self).reduce(
return super().reduce(
func, dim, keep_attrs, **kwargs)


Expand Down
4 changes: 2 additions & 2 deletions xarray/core/rolling.py
Expand Up @@ -178,7 +178,7 @@ def __init__(self, obj, windows, min_periods=None, center=False):
Dataset.rolling
Dataset.groupby
"""
super(DataArrayRolling, self).__init__(
super().__init__(
obj, windows, min_periods=min_periods, center=center)

self.window_labels = self.obj[self.dim]
Expand Down Expand Up @@ -401,7 +401,7 @@ def __init__(self, obj, windows, min_periods=None, center=False):
Dataset.groupby
DataArray.groupby
"""
super(DatasetRolling, self).__init__(obj, windows, min_periods, center)
super().__init__(obj, windows, min_periods, center)
if self.dim not in self.obj.dims:
raise KeyError(self.dim)
# Keep each Rolling object as an OrderedDict
Expand Down
5 changes: 2 additions & 3 deletions xarray/core/variable.py
Expand Up @@ -1840,8 +1840,7 @@ class IndexVariable(Variable):
"""

def __init__(self, dims, data, attrs=None, encoding=None, fastpath=False):
super(IndexVariable, self).__init__(dims, data, attrs, encoding,
fastpath)
super().__init__(dims, data, attrs, encoding, fastpath)
if self.ndim != 1:
raise ValueError('%s objects must be 1-dimensional' %
type(self).__name__)
Expand Down Expand Up @@ -1959,7 +1958,7 @@ def copy(self, deep=True, data=None):
def equals(self, other, equiv=None):
# if equiv is specified, super up
if equiv is not None:
return super(IndexVariable, self).equals(other, equiv)
return super().equals(other, equiv)

# otherwise use the native index equals, rather than looking at _data
other = getattr(other, 'variable', other)
Expand Down
8 changes: 4 additions & 4 deletions xarray/tests/test_backends.py
Expand Up @@ -1656,7 +1656,7 @@ def test_encoding_kwarg_fixed_width_string(self):
# makes sense for Zarr backend
@pytest.mark.xfail(reason="Zarr caching not implemented")
def test_dataset_caching(self):
super(CFEncodedBase, self).test_dataset_caching()
super().test_dataset_caching()

def test_append_write(self):
ds, ds_to_append, _ = create_append_test_data()
Expand All @@ -1668,7 +1668,7 @@ def test_append_write(self):

@pytest.mark.xfail(reason="Zarr stores can not be appended to")
def test_append_overwrite_values(self):
super(CFEncodedBase, self).test_append_overwrite_values()
super().test_append_overwrite_values()

def test_append_with_invalid_dim_raises(self):

Expand Down Expand Up @@ -1825,13 +1825,13 @@ def test_append_write(self):
import scipy
if scipy.__version__ == '1.0.1':
pytest.xfail('https://github.com/scipy/scipy/issues/8625')
super(ScipyWriteBase, self).test_append_write()
super().test_append_write()

def test_append_overwrite_values(self):
import scipy
if scipy.__version__ == '1.0.1':
pytest.xfail('https://github.com/scipy/scipy/issues/8625')
super(ScipyWriteBase, self).test_append_overwrite_values()
super().test_append_overwrite_values()


@requires_scipy
Expand Down
5 changes: 2 additions & 3 deletions xarray/tests/test_dataset.py
Expand Up @@ -112,12 +112,11 @@ def create_test_multiindex():

class InaccessibleVariableDataStore(backends.InMemoryDataStore):
def __init__(self):
super(InaccessibleVariableDataStore, self).__init__()
super().__init__()
self._indexvars = set()

def store(self, variables, *args, **kwargs):
super(InaccessibleVariableDataStore, self).store(
variables, *args, **kwargs)
super().store(variables, *args, **kwargs)
for k, v in variables.items():
if isinstance(v, IndexVariable):
self._indexvars.add(k)
Expand Down
28 changes: 14 additions & 14 deletions xarray/tests/test_variable.py
Expand Up @@ -1776,32 +1776,32 @@ class TestVariableWithDask(VariableSubclassobjects):

@pytest.mark.xfail
def test_0d_object_array_with_list(self):
super(TestVariableWithDask, self).test_0d_object_array_with_list()
super().test_0d_object_array_with_list()

@pytest.mark.xfail
def test_array_interface(self):
# dask array does not have `argsort`
super(TestVariableWithDask, self).test_array_interface()
super().test_array_interface()

@pytest.mark.xfail
def test_copy_index(self):
super(TestVariableWithDask, self).test_copy_index()
super().test_copy_index()

@pytest.mark.xfail
def test_eq_all_dtypes(self):
super(TestVariableWithDask, self).test_eq_all_dtypes()
super().test_eq_all_dtypes()

def test_getitem_fancy(self):
super(TestVariableWithDask, self).test_getitem_fancy()
super().test_getitem_fancy()

def test_getitem_1d_fancy(self):
super(TestVariableWithDask, self).test_getitem_1d_fancy()
super().test_getitem_1d_fancy()

def test_equals_all_dtypes(self):
import dask
if '0.18.2' <= LooseVersion(dask.__version__) < '0.19.1':
pytest.xfail('https://github.com/pydata/xarray/issues/2318')
super(TestVariableWithDask, self).test_equals_all_dtypes()
super().test_equals_all_dtypes()

def test_getitem_with_mask_nd_indexer(self):
import dask.array as da
Expand Down Expand Up @@ -1901,31 +1901,31 @@ def test_datetime64(self):
# IndexVariable objects:
@pytest.mark.xfail
def test_getitem_error(self):
super(TestIndexVariable, self).test_getitem_error()
super().test_getitem_error()

@pytest.mark.xfail
def test_getitem_advanced(self):
super(TestIndexVariable, self).test_getitem_advanced()
super().test_getitem_advanced()

@pytest.mark.xfail
def test_getitem_fancy(self):
super(TestIndexVariable, self).test_getitem_fancy()
super().test_getitem_fancy()

@pytest.mark.xfail
def test_getitem_uint(self):
super(TestIndexVariable, self).test_getitem_fancy()
super().test_getitem_fancy()

@pytest.mark.xfail
def test_pad(self):
super(TestIndexVariable, self).test_rolling_window()
super().test_rolling_window()

@pytest.mark.xfail
def test_rolling_window(self):
super(TestIndexVariable, self).test_rolling_window()
super().test_rolling_window()

@pytest.mark.xfail
def test_coarsen_2d(self):
super(TestIndexVariable, self).test_coarsen_2d()
super().test_coarsen_2d()


class TestAsCompatibleData:
Expand Down

0 comments on commit 378c330

Please sign in to comment.