Skip to content

Commit 1be777f

Browse files
authored
update isort CI and pre-commit hook (#4204)
* don't use the removed isort flag * update the isort hook * remove the recursive flag from the pull request template * remove the recursive flag from the contributing guide * unpin isort * update the isort pre-commit hook * apply isort which now also formats imports in functions * update the flake8 pre-commit hook to get mypy overloads to pass
1 parent 52043bc commit 1be777f

25 files changed

+41
-34
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
- [ ] Closes #xxxx
44
- [ ] Tests added
5-
- [ ] Passes `isort -rc . && black . && mypy . && flake8`
5+
- [ ] Passes `isort . && black . && mypy . && flake8`
66
- [ ] User visible changes (including notable bug fixes) are documented in `whats-new.rst`
77
- [ ] New functions/methods are listed in `api.rst`

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
repos:
33
# isort should run before black as black sometimes tweaks the isort output
44
- repo: https://github.com/timothycrosley/isort
5-
rev: 4.3.21-2
5+
rev: 5.1.0
66
hooks:
77
- id: isort
8-
files: .+\.py$
98
# https://github.com/python/black#version-control-integration
109
- repo: https://github.com/python/black
1110
rev: stable
@@ -16,7 +15,7 @@ repos:
1615
hooks:
1716
- id: blackdoc
1817
- repo: https://gitlab.com/pycqa/flake8
19-
rev: 3.7.9
18+
rev: 3.8.3
2019
hooks:
2120
- id: flake8
2221
- repo: https://github.com/pre-commit/mirrors-mypy

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
- template: ci/azure/install.yml
9696
- bash: |
9797
source activate xarray-tests
98-
isort -rc --check .
98+
isort --check .
9999
displayName: isort formatting checks
100100
101101
- job: MinimumVersionsPolicy

ci/requirements/py36-min-all-deps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dependencies:
2323
- hdf5=1.10
2424
- hypothesis
2525
- iris=2.2
26-
- isort=4.3.21
26+
- isort
2727
- lxml=4.4 # Optional dep of pydap
2828
- matplotlib=3.1
2929
- mypy=0.761 # Must match .pre-commit-config.yaml

ci/requirements/py36.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies:
1919
- hdf5
2020
- hypothesis
2121
- iris
22-
- isort=4.3.21
22+
- isort
2323
- lxml # Optional dep of pydap
2424
- matplotlib
2525
- mypy=0.761 # Must match .pre-commit-config.yaml

ci/requirements/py37-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies:
1919
- hdf5
2020
- hypothesis
2121
- iris
22-
- isort=4.3.21
22+
- isort
2323
- lxml # Optional dep of pydap
2424
- matplotlib
2525
- mypy=0.761 # Must match .pre-commit-config.yaml

ci/requirements/py37.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies:
1919
- hdf5
2020
- hypothesis
2121
- iris
22-
- isort=4.3.21
22+
- isort
2323
- lxml # Optional dep of pydap
2424
- matplotlib
2525
- mypy=0.761 # Must match .pre-commit-config.yaml

ci/requirements/py38-all-but-dask.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dependencies:
1616
- h5py
1717
- hdf5
1818
- hypothesis
19-
- isort=4.3.21
19+
- isort
2020
- lxml # Optional dep of pydap
2121
- matplotlib
2222
- mypy=0.761 # Must match .pre-commit-config.yaml

ci/requirements/py38.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies:
1919
- hdf5
2020
- hypothesis
2121
- iris
22-
- isort=4.3.21
22+
- isort
2323
- lxml # Optional dep of pydap
2424
- matplotlib
2525
- mypy=0.780 # Must match .pre-commit-config.yaml

conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def pytest_runtest_setup(item):
2727
def add_standard_imports(doctest_namespace):
2828
import numpy as np
2929
import pandas as pd
30+
3031
import xarray as xr
3132

3233
doctest_namespace["np"] = np

doc/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ xarray uses several tools to ensure a consistent code format throughout the proj
368368

369369
and then run from the root of the Xarray repository::
370370

371-
isort -rc .
371+
isort .
372372
black -t py36 .
373373
blackdoc -t py36 .
374374
flake8

xarray/backends/scipy_.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ def __setitem__(self, key, value):
5757

5858

5959
def _open_scipy_netcdf(filename, mode, mmap, version):
60-
import scipy.io
6160
import gzip
6261

62+
import scipy.io
63+
6364
# if the string ends with .gz, then gunzip and open as netcdf file
6465
if isinstance(filename, str) and filename.endswith(".gz"):
6566
try:

xarray/conventions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,8 @@ def decode_cf(
567567
-------
568568
decoded : Dataset
569569
"""
570-
from .core.dataset import Dataset
571570
from .backends.common import AbstractDataStore
571+
from .core.dataset import Dataset
572572

573573
if isinstance(obj, Dataset):
574574
vars = obj._variables

xarray/convert.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ def from_iris(cube):
254254
""" Convert a Iris cube into an DataArray
255255
"""
256256
import iris.exceptions
257+
257258
from xarray.core.pycompat import dask_array_type
258259

259260
name = _name(cube)

xarray/core/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,9 +1088,9 @@ def resample(
10881088
"""
10891089
# TODO support non-string indexer after removing the old API.
10901090

1091+
from ..coding.cftimeindex import CFTimeIndex
10911092
from .dataarray import DataArray
10921093
from .resample import RESAMPLE_DIM
1093-
from ..coding.cftimeindex import CFTimeIndex
10941094

10951095
if keep_attrs is None:
10961096
keep_attrs = _get_keep_attrs(default=False)
@@ -1283,8 +1283,8 @@ def isin(self, test_elements):
12831283
numpy.isin
12841284
"""
12851285
from .computation import apply_ufunc
1286-
from .dataset import Dataset
12871286
from .dataarray import DataArray
1287+
from .dataset import Dataset
12881288
from .variable import Variable
12891289

12901290
if isinstance(test_elements, Dataset):

xarray/core/computation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,8 @@ def earth_mover_distance(first_samples,
976976
.. [2] http://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html
977977
.. [3] http://xarray.pydata.org/en/stable/computation.html#wrapping-custom-computation
978978
"""
979-
from .groupby import GroupBy
980979
from .dataarray import DataArray
980+
from .groupby import GroupBy
981981
from .variable import Variable
982982

983983
if input_core_dims is None:

xarray/core/concat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def concat(
116116
# TODO: add ignore_index arguments copied from pandas.concat
117117
# TODO: support concatenating scalar coordinates even if the concatenated
118118
# dimension already exists
119-
from .dataset import Dataset
120119
from .dataarray import DataArray
120+
from .dataset import Dataset
121121

122122
try:
123123
first_obj, objs = utils.peek_at(objs)

xarray/core/dataset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4144,7 +4144,7 @@ def interpolate_na(
41444144
numpy.interp
41454145
scipy.interpolate
41464146
"""
4147-
from .missing import interp_na, _apply_over_vars_with_dim
4147+
from .missing import _apply_over_vars_with_dim, interp_na
41484148

41494149
new = _apply_over_vars_with_dim(
41504150
interp_na,
@@ -4178,7 +4178,7 @@ def ffill(self, dim: Hashable, limit: int = None) -> "Dataset":
41784178
-------
41794179
Dataset
41804180
"""
4181-
from .missing import ffill, _apply_over_vars_with_dim
4181+
from .missing import _apply_over_vars_with_dim, ffill
41824182

41834183
new = _apply_over_vars_with_dim(ffill, self, dim=dim, limit=limit)
41844184
return new
@@ -4203,7 +4203,7 @@ def bfill(self, dim: Hashable, limit: int = None) -> "Dataset":
42034203
-------
42044204
Dataset
42054205
"""
4206-
from .missing import bfill, _apply_over_vars_with_dim
4206+
from .missing import _apply_over_vars_with_dim, bfill
42074207

42084208
new = _apply_over_vars_with_dim(bfill, self, dim=dim, limit=limit)
42094209
return new

xarray/core/groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def unique_value_groups(ar, sort=True):
6464

6565

6666
def _dummy_copy(xarray_obj):
67-
from .dataset import Dataset
6867
from .dataarray import DataArray
68+
from .dataset import Dataset
6969

7070
if isinstance(xarray_obj, Dataset):
7171
res = Dataset(

xarray/core/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def _expand_slice(slice_, size):
5050

5151

5252
def _sanitize_slice_element(x):
53-
from .variable import Variable
5453
from .dataarray import DataArray
54+
from .variable import Variable
5555

5656
if isinstance(x, (Variable, DataArray)):
5757
x = x.values

xarray/core/nanops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
try:
88
import dask.array as dask_array
9+
910
from . import dask_array_compat
1011
except ImportError:
1112
dask_array = None
@@ -118,7 +119,7 @@ def nansum(a, axis=None, dtype=None, out=None, min_count=None):
118119

119120
def _nanmean_ddof_object(ddof, value, axis=None, dtype=None, **kwargs):
120121
""" In house nanmean. ddof argument will be used in _nanvar method """
121-
from .duck_array_ops import count, fillna, _dask_or_eager_func, where_method
122+
from .duck_array_ops import _dask_or_eager_func, count, fillna, where_method
122123

123124
valid_count = count(value, axis=axis)
124125
value = fillna(value, 0)

xarray/core/parallel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import dask
33
import dask.array
44
from dask.highlevelgraph import HighLevelGraph
5+
56
from .dask_array_compat import meta_from_array
67

78
except ImportError:

xarray/tests/test_backends.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,7 +3207,7 @@ def test_load_dataarray(self):
32073207
@pytest.mark.filterwarnings("ignore:The binary mode of fromstring is deprecated")
32083208
class TestPydap:
32093209
def convert_to_pydap_dataset(self, original):
3210-
from pydap.model import GridType, BaseType, DatasetType
3210+
from pydap.model import BaseType, DatasetType, GridType
32113211

32123212
ds = DatasetType("bears", **original.attrs)
32133213
for key, var in original.data_vars.items():
@@ -3747,9 +3747,10 @@ def test_platecarree(self):
37473747

37483748
def test_notransform(self):
37493749
# regression test for https://github.com/pydata/xarray/issues/1686
3750-
import rasterio
37513750
import warnings
37523751

3752+
import rasterio
3753+
37533754
# Create a geotiff file
37543755
with warnings.catch_warnings():
37553756
# rasterio throws a NotGeoreferencedWarning here, which is
@@ -4097,8 +4098,8 @@ def test_rasterio_vrt_with_transform_and_size(self):
40974098
# Test open_rasterio() support of WarpedVRT with transform, width and
40984099
# height (issue #2864)
40994100
import rasterio
4100-
from rasterio.warp import calculate_default_transform
41014101
from affine import Affine
4102+
from rasterio.warp import calculate_default_transform
41024103

41034104
with create_tmp_geotiff() as (tmp_file, expected):
41044105
with rasterio.open(tmp_file) as src:

xarray/tests/test_coding_times.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,10 @@ def test_decode_non_standard_calendar_inside_timestamp_range(calendar):
222222
@requires_cftime
223223
@pytest.mark.parametrize("calendar", _ALL_CALENDARS)
224224
def test_decode_dates_outside_timestamp_range(calendar):
225-
import cftime
226225
from datetime import datetime
227226

227+
import cftime
228+
228229
units = "days since 0001-01-01"
229230
times = [datetime(1, 4, 1, h) for h in range(1, 5)]
230231
time = cftime.date2num(times, units, calendar=calendar)
@@ -358,9 +359,10 @@ def test_decode_nonstandard_calendar_multidim_time_inside_timestamp_range(calend
358359
@requires_cftime
359360
@pytest.mark.parametrize("calendar", _ALL_CALENDARS)
360361
def test_decode_multidim_time_outside_timestamp_range(calendar):
361-
import cftime
362362
from datetime import datetime
363363

364+
import cftime
365+
364366
units = "days since 0001-01-01"
365367
times1 = [datetime(1, 4, day) for day in range(1, 6)]
366368
times2 = [datetime(1, 5, day) for day in range(1, 6)]

xarray/tests/test_dataarray.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6417,8 +6417,8 @@ def test_name_in_masking():
64176417
class TestIrisConversion:
64186418
@requires_iris
64196419
def test_to_and_from_iris(self):
6420-
import iris
64216420
import cf_units # iris requirement
6421+
import iris
64226422

64236423
# to iris
64246424
coord_dict = {}
@@ -6488,9 +6488,9 @@ def test_to_and_from_iris(self):
64886488
@requires_iris
64896489
@requires_dask
64906490
def test_to_and_from_iris_dask(self):
6491+
import cf_units # iris requirement
64916492
import dask.array as da
64926493
import iris
6493-
import cf_units # iris requirement
64946494

64956495
coord_dict = {}
64966496
coord_dict["distance"] = ("distance", [-2, 2], {"units": "meters"})
@@ -6623,8 +6623,8 @@ def test_da_name_from_cube(self, std_name, long_name, var_name, name, attrs):
66236623
],
66246624
)
66256625
def test_da_coord_name_from_cube(self, std_name, long_name, var_name, name, attrs):
6626-
from iris.cube import Cube
66276626
from iris.coords import DimCoord
6627+
from iris.cube import Cube
66286628

66296629
latitude = DimCoord(
66306630
[-90, 0, 90], standard_name=std_name, var_name=var_name, long_name=long_name
@@ -6637,8 +6637,8 @@ def test_da_coord_name_from_cube(self, std_name, long_name, var_name, name, attr
66376637

66386638
@requires_iris
66396639
def test_prevent_duplicate_coord_names(self):
6640-
from iris.cube import Cube
66416640
from iris.coords import DimCoord
6641+
from iris.cube import Cube
66426642

66436643
# Iris enforces unique coordinate names. Because we use a different
66446644
# name resolution order a valid iris Cube with coords that have the
@@ -6659,8 +6659,8 @@ def test_prevent_duplicate_coord_names(self):
66596659
[["IA", "IL", "IN"], [0, 2, 1]], # non-numeric values # non-monotonic values
66606660
)
66616661
def test_fallback_to_iris_AuxCoord(self, coord_values):
6662-
from iris.cube import Cube
66636662
from iris.coords import AuxCoord
6663+
from iris.cube import Cube
66646664

66656665
data = [0, 0, 0]
66666666
da = xr.DataArray(data, coords=[coord_values], dims=["space"])

0 commit comments

Comments
 (0)