Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black #3142

Merged
merged 15 commits into from
Aug 8, 2019
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

- [ ] Closes #xxxx
- [ ] Tests added
- [ ] Passes `black .` & `flake8`
- [ ] Fully documented, including `whats-new.rst` for all changes and `api.rst` for new API
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://pre-commit.com/
# https://github.com/python/black#version-control-integration
repos:
- repo: https://github.com/python/black
rev: stable
hooks:
- id: black
language_version: python3.7
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.2.3
hooks:
- id: flake8
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ xarray: N-D labeled arrays and datasets
:target: https://pandas.pydata.org/speed/xarray/
.. image:: https://img.shields.io/pypi/v/xarray.svg
:target: https://pypi.python.org/pypi/xarray/
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/python/black


**xarray** (formerly **xray**) is an open source project and Python package
that makes working with labelled multi-dimensional arrays simple,
Expand Down
2 changes: 2 additions & 0 deletions asv_bench/benchmarks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def decorator(func):
func.param_names = names
func.params = params
return func

return decorator


Expand All @@ -28,6 +29,7 @@ def randn(shape, frac_nan=None, chunks=None, seed=0):
x = rng.standard_normal(shape)
else:
import dask.array as da

rng = da.random.RandomState(seed)
x = rng.standard_normal(shape, chunks=chunks)

Expand Down
18 changes: 9 additions & 9 deletions asv_bench/benchmarks/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ def setup(self):
data = np.random.randn(t_size, x_size, y_size)

self.dsA0 = xr.Dataset(
{'A': xr.DataArray(data, coords={'T': t},
dims=('T', 'X', 'Y'))})
{"A": xr.DataArray(data, coords={"T": t}, dims=("T", "X", "Y"))}
)
self.dsA1 = xr.Dataset(
{'A': xr.DataArray(data, coords={'T': t + t_size},
dims=('T', 'X', 'Y'))})
{"A": xr.DataArray(data, coords={"T": t + t_size}, dims=("T", "X", "Y"))}
)
self.dsB0 = xr.Dataset(
{'B': xr.DataArray(data, coords={'T': t},
dims=('T', 'X', 'Y'))})
{"B": xr.DataArray(data, coords={"T": t}, dims=("T", "X", "Y"))}
)
self.dsB1 = xr.Dataset(
{'B': xr.DataArray(data, coords={'T': t + t_size},
dims=('T', 'X', 'Y'))})
{"B": xr.DataArray(data, coords={"T": t + t_size}, dims=("T", "X", "Y"))}
)

def time_combine_manual(self):
datasets = [[self.dsA0, self.dsA1], [self.dsB0, self.dsB1]]

xr.combine_manual(datasets, concat_dim=[None, 't'])
xr.combine_manual(datasets, concat_dim=[None, "t"])

def time_auto_combine(self):
"""Also has to load and arrange t coordinate"""
Expand Down
43 changes: 24 additions & 19 deletions asv_bench/benchmarks/dataarray_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

def make_bench_data(shape, frac_nan, chunks):
vals = randn(shape, frac_nan)
coords = {'time': pd.date_range('2000-01-01', freq='D',
periods=shape[0])}
da = xr.DataArray(vals, dims=('time', 'x', 'y'), coords=coords)
coords = {"time": pd.date_range("2000-01-01", freq="D", periods=shape[0])}
da = xr.DataArray(vals, dims=("time", "x", "y"), coords=coords)

if chunks is not None:
da = da.chunk(chunks)
Expand All @@ -28,44 +27,50 @@ def time_interpolate_na(shape, chunks, method, limit):
if chunks is not None:
requires_dask()
da = make_bench_data(shape, 0.1, chunks=chunks)
actual = da.interpolate_na(dim='time', method='linear', limit=limit)
actual = da.interpolate_na(dim="time", method="linear", limit=limit)

if chunks is not None:
actual = actual.compute()


time_interpolate_na.param_names = ['shape', 'chunks', 'method', 'limit']
time_interpolate_na.params = ([(3650, 200, 400), (100, 25, 25)],
[None, {'x': 25, 'y': 25}],
['linear', 'spline', 'quadratic', 'cubic'],
[None, 3])
time_interpolate_na.param_names = ["shape", "chunks", "method", "limit"]
time_interpolate_na.params = (
[(3650, 200, 400), (100, 25, 25)],
[None, {"x": 25, "y": 25}],
["linear", "spline", "quadratic", "cubic"],
[None, 3],
)


def time_ffill(shape, chunks, limit):

da = make_bench_data(shape, 0.1, chunks=chunks)
actual = da.ffill(dim='time', limit=limit)
actual = da.ffill(dim="time", limit=limit)

if chunks is not None:
actual = actual.compute()


time_ffill.param_names = ['shape', 'chunks', 'limit']
time_ffill.params = ([(3650, 200, 400), (100, 25, 25)],
[None, {'x': 25, 'y': 25}],
[None, 3])
time_ffill.param_names = ["shape", "chunks", "limit"]
time_ffill.params = (
[(3650, 200, 400), (100, 25, 25)],
[None, {"x": 25, "y": 25}],
[None, 3],
)


def time_bfill(shape, chunks, limit):

da = make_bench_data(shape, 0.1, chunks=chunks)
actual = da.bfill(dim='time', limit=limit)
actual = da.bfill(dim="time", limit=limit)

if chunks is not None:
actual = actual.compute()


time_bfill.param_names = ['shape', 'chunks', 'limit']
time_bfill.params = ([(3650, 200, 400), (100, 25, 25)],
[None, {'x': 25, 'y': 25}],
[None, 3])
time_bfill.param_names = ["shape", "chunks", "limit"]
time_bfill.params = (
[(3650, 200, 400), (100, 25, 25)],
[None, {"x": 25, "y": 25}],
[None, 3],
)
Loading