Skip to content

Commit

Permalink
black: Move config to pyproject.toml and update version (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Sep 9, 2020
1 parent 5386ba8 commit 8f7737b
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 44 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
rev: v3.2.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 19.10b0
rev: 20.8b1
hooks:
- id: black
- repo: https://github.com/asottile/seed-isort-config
rev: v2.1.0
rev: v2.2.0
hooks:
- id: seed-isort-config
- repo: https://github.com/timothycrosley/isort
rev: 4.3.21
rev: 5.5.1
hooks:
- id: isort
args: [setup.py, rioxarray/, test/, docs/]
- repo: https://github.com/asottile/blacken-docs
rev: v1.6.0
rev: v1.8.0
hooks:
- id: blacken-docs
args: [--skip-errors]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
rev: 3.8.3
hooks:
- id: flake8
args: [--max-line-length, '88', --ignore, "E225,W503,C408"]
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Ready to contribute? Here's how to set up `rioxarray` for local development.

$ flake8 --ignore=E731,W503,W504 --exclude --max-complexity 10 --max-line-length 88 rioxarray/
$ flake8 --max-line-length 88 tests/unit/ tests/functional/ tests/integration
$ black --target-version py36 --check .
$ black --check .
$ py.test

7. Commit your changes and push your branch to GitLab::
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ clean-docs: ## remove builds

lint: ## check style with flake8
flake8 rioxarray test --max-line-length 88
black --target-version py36 --check .
black --check .

check:
###### FLAKE8 #####
# No unused imports, no undefined vars,
flake8 --ignore=E731,W503,W504 --exclude --max-complexity 10 --max-line-length 88 rioxarray/
flake8 --max-line-length 88 tests/unit/ tests/functional/ tests/integration
black --target-version py36 --check .
black --check .

pylint:
###### PYLINT ######
Expand Down Expand Up @@ -92,5 +92,4 @@ install: clean ## install the package to the active Python's site-packages
python setup.py install

install-dev: clean ## install development version to active Python's site-packages
pip install -U -r requirements.txt -r requirements_dev.txt
pip install -e .[all]
5 changes: 3 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ channels:
- conda-forge
- defaults
dependencies:
- python=3.6
- rasterio=1.0.*
- python=3.7
- rasterio
- scipy
- xarray
- netcdf4
- dask
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
# Minimum requirements for the build system to execute.
requires = ["setuptools", "wheel"]

[tool.black]
target_version = ['py36']
4 changes: 2 additions & 2 deletions rioxarray/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def shape(self):
return self._shape

def _get_indexer(self, key):
""" Get indexer for rasterio array.
"""Get indexer for rasterio array.
Parameter
---------
Expand Down Expand Up @@ -538,8 +538,8 @@ def _prepare_dask(result, riods, filename, chunks):
mtime = None

if chunks in (True, "auto"):
from dask.array.core import normalize_chunks
import dask
from dask.array.core import normalize_chunks

if LooseVersion(dask.__version__) < LooseVersion("0.18.0"):
msg = (
Expand Down
2 changes: 1 addition & 1 deletion rioxarray/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def merge_arrays(
representative_array = dataarrays[0]
if parse_coordinates:
coords = _make_coords(
representative_array, merged_transform, merged_shape[-1], merged_shape[-2],
representative_array, merged_transform, merged_shape[-1], merged_shape[-2]
)
else:
coords = _get_nonspatial_coords(representative_array)
Expand Down
14 changes: 6 additions & 8 deletions rioxarray/rioxarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def add_xy_grid_meta(coords, crs=None):

def add_spatial_ref(in_ds, dst_crs, grid_mapping_name):
warnings.warn(
"add_spatial_ref is deprecated. Use rio.write_crs instead.", DeprecationWarning,
"add_spatial_ref is deprecated. Use rio.write_crs instead.", DeprecationWarning
)
in_ds.rio.write_crs(
input_crs=dst_crs, grid_mapping_name=grid_mapping_name, inplace=True
Expand All @@ -152,9 +152,7 @@ def _add_attrs_proj(new_data_array, src_data_array):
new_data_array.rio.set_attrs(new_attrs, inplace=True)

# make sure projection added
new_data_array.rio.write_crs(
src_data_array.rio.crs, inplace=True,
)
new_data_array.rio.write_crs(src_data_array.rio.crs, inplace=True)
new_data_array.rio.write_coordinate_system(inplace=True)
new_data_array.rio.write_transform(inplace=True)
# make sure encoding added
Expand Down Expand Up @@ -332,7 +330,7 @@ def __init__(self, xarray_obj):
@property
def crs(self):
""":obj:`rasterio.crs.CRS`:
Retrieve projection from :obj:`xarray.Dataset` | :obj:`xarray.DataArray`
Retrieve projection from :obj:`xarray.Dataset` | :obj:`xarray.DataArray`
"""
if self._crs is not None:
return None if self._crs is False else self._crs
Expand Down Expand Up @@ -523,7 +521,7 @@ def _cached_transform(self):
# look in grid_mapping
return Affine.from_gdal(
*np.fromstring(
self._obj.coords[self.grid_mapping].attrs["GeoTransform"], sep=" ",
self._obj.coords[self.grid_mapping].attrs["GeoTransform"], sep=" "
)
)
except KeyError:
Expand Down Expand Up @@ -1751,7 +1749,7 @@ def vars(self):
@property
def crs(self):
""":obj:`rasterio.crs.CRS`:
Retrieve projection from `xarray.Dataset`
Retrieve projection from `xarray.Dataset`
"""
if self._crs is not None:
return None if self._crs is False else self._crs
Expand Down Expand Up @@ -1886,7 +1884,7 @@ def pad_box(self, minx, miny, maxx, maxy):
padded_dataset[var] = (
self._obj[var]
.rio.set_spatial_dims(x_dim=self.x_dim, y_dim=self.y_dim, inplace=True)
.rio.pad_box(minx, miny, maxx, maxy,)
.rio.pad_box(minx, miny, maxx, maxy)
)
return padded_dataset.rio.set_spatial_dims(
x_dim=self.x_dim, y_dim=self.y_dim, inplace=True
Expand Down
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _assert_attrs_equal(input_xr, compare_xr, decimal_precision):


def _assert_xarrays_equal(
input_xarray, compare_xarray, precision=7, skip_xy_check=False,
input_xarray, compare_xarray, precision=7, skip_xy_check=False
):
_assert_attrs_equal(input_xarray, compare_xarray, precision)
if hasattr(input_xarray, "variables"):
Expand Down
30 changes: 10 additions & 20 deletions test/integration/test_integration_rioxarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,7 @@ def test_clip_box__nodata_error(modis_clip):
var_match = ""
if hasattr(xdi, "name") and xdi.name:
var_match = " Data variable: __xarray_dataarray_variable__"
with pytest.raises(
NoDataInBounds, match=var_match,
):
with pytest.raises(NoDataInBounds, match=var_match):
xdi.rio.clip_box(
minx=-8272735.53951584, # xdi.x[5].values
miny=8048371.187465771, # xdi.y[7].values
Expand Down Expand Up @@ -792,11 +790,11 @@ def test_make_coords__calc_trans(open_func, modis_reproject):
# calculate coordinates from the calculated transform
width, height = xdi.rio.shape
calculated_transform = xdi.rio.transform(recalc=True)
calc_coords_calc_trans = _make_coords(xdi, calculated_transform, width, height,)
calc_coords_calc_trans = _make_coords(xdi, calculated_transform, width, height)
widthr, heightr = xri.rio.shape
calculated_transformr = xri.rio.transform(recalc=True)
calc_coords_calc_transr = _make_coords(
xri, calculated_transformr, widthr, heightr,
xri, calculated_transformr, widthr, heightr
)

assert_almost_equal(calculated_transform, calculated_transformr)
Expand Down Expand Up @@ -832,11 +830,11 @@ def test_make_coords__attr_trans(open_func, modis_reproject):
# calculate coordinates from the attribute transform
width, height = xdi.rio.shape
attr_transform = xdi.rio.transform()
calc_coords_attr_trans = _make_coords(xdi, attr_transform, width, height,)
calc_coords_attr_trans = _make_coords(xdi, attr_transform, width, height)
widthr, heightr = xri.rio.shape
calculated_transformr = xri.rio.transform()
calc_coords_calc_transr = _make_coords(
xri, calculated_transformr, widthr, heightr,
xri, calculated_transformr, widthr, heightr
)
assert_almost_equal(attr_transform, calculated_transformr)
# check to see if they all match
Expand Down Expand Up @@ -1256,7 +1254,7 @@ def test_to_raster__dataset__different_crs(tmpdir):
def test_to_raster__dataset__different_nodata(tmpdir):
tmp_raster = tmpdir.join("planet_3d_raster.tif")
with xarray.open_dataset(
os.path.join(TEST_INPUT_DATA_DIR, "PLANET_SCOPE_3D.nc"), mask_and_scale=False,
os.path.join(TEST_INPUT_DATA_DIR, "PLANET_SCOPE_3D.nc"), mask_and_scale=False
) as mda:
rds = mda.isel(time=0)
rds.green.rio.write_nodata(1234, inplace=True)
Expand Down Expand Up @@ -1827,13 +1825,9 @@ def test_nonstandard_dims_error_msg():
) as xds:
xds.coords["lon"].attrs = {}
xds.coords["lat"].attrs = {}
with pytest.raises(
DimensionError, match="x dimension not found",
):
with pytest.raises(DimensionError, match="x dimension not found"):
xds.rio.width
with pytest.raises(
DimensionError, match="Data variable: analysed_sst",
):
with pytest.raises(DimensionError, match="Data variable: analysed_sst"):
xds.analysed_sst.rio.width


Expand Down Expand Up @@ -1881,15 +1875,11 @@ def test_missing_crs_error_msg():
) as xds:
xds = xds.drop_vars("spatial_ref")
xds.attrs.pop("grid_mapping")
with pytest.raises(
MissingCRS, match="Data variable: analysed_sst",
):
with pytest.raises(MissingCRS, match="Data variable: analysed_sst"):
xds.rio.set_spatial_dims(x_dim="lon", y_dim="lat").rio.reproject(
"EPSG:4326"
)
with pytest.raises(
MissingCRS, match="Data variable: analysed_sst",
):
with pytest.raises(MissingCRS, match="Data variable: analysed_sst"):
xds.rio.set_spatial_dims(
x_dim="lon", y_dim="lat"
).analysed_sst.rio.reproject("EPSG:4326")
Expand Down

0 comments on commit 8f7737b

Please sign in to comment.