Skip to content

Commit 8dfa801

Browse files
authored
Linting: mdformat, nbQA (#325)
1 parent 88eff83 commit 8dfa801

24 files changed

+5267
-5187
lines changed

.pre-commit-config.yaml

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ ci:
22
autoupdate_schedule: quarterly
33

44
repos:
5-
# isort should run before black as black sometimes tweaks the isort output
65
- repo: https://github.com/PyCQA/isort
76
rev: 5.10.1
87
hooks:
98
- id: isort
109
files: .+\.py$
1110

12-
# https://github.com/python/black#version-control-integration
1311
- repo: https://github.com/psf/black
1412
rev: 22.3.0
1513
hooks:
@@ -26,22 +24,49 @@ repos:
2624
- id: mypy
2725
additional_dependencies: [types-all]
2826

29-
- repo: https://github.com/deathbeds/prenotebook
30-
rev: f5bdb72a400f1a56fe88109936c83aa12cc349fa
31-
hooks:
32-
- id: prenotebook
33-
3427
- repo: https://github.com/myint/rstcheck
3528
rev: 3f92957478422df87bd730abde66f089cc1ee19b
3629
hooks:
3730
- id: rstcheck
3831

39-
# run this occasionally, ref discussion https://github.com/pydata/xarray/pull/3194
40-
# - repo: https://github.com/asottile/pyupgrade
41-
# rev: v1.22.1
42-
# hooks:
43-
# - id: pyupgrade
44-
# args:
45-
# - "--py3-only"
46-
# # remove on f-strings in Py3.7
47-
# - "--keep-percent-format"
32+
- repo: https://github.com/executablebooks/mdformat
33+
rev: 0.7.14
34+
hooks:
35+
- id: mdformat
36+
additional_dependencies:
37+
- mdformat-black
38+
- mdformat-myst
39+
40+
- repo: https://github.com/nbQA-dev/nbQA
41+
rev: 1.3.1
42+
hooks:
43+
- id: nbqa-black
44+
- id: nbqa-pyupgrade
45+
args: [--py37-plus]
46+
- id: nbqa-isort
47+
- id: nbqa
48+
entry: nbqa mdformat
49+
name: nbqa-mdformat
50+
alias: nbqa-mdformat
51+
additional_dependencies: [mdformat==0.7.14]
52+
53+
- repo: https://github.com/asottile/pyupgrade
54+
rev: v2.31.1
55+
hooks:
56+
- id: pyupgrade
57+
args:
58+
- "--py37-plus"
59+
60+
- repo: https://github.com/pre-commit/pre-commit-hooks
61+
rev: v4.1.0
62+
hooks:
63+
- id: trailing-whitespace
64+
- id: end-of-file-fixer
65+
- id: check-toml
66+
- id: check-yaml
67+
68+
- repo: https://github.com/keewis/blackdoc
69+
rev: v0.3.4
70+
hooks:
71+
- id: blackdoc
72+
files: .+\.py$

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ exclude .tributors
1313
exclude .zenodo.json
1414
exclude *.yml
1515
exclude *.yaml
16-
exclude .gitignore
16+
exclude .gitignore

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
cf-xarray
3333
=========
3434

35-
A lightweight convenience wrapper for using CF attributes on xarray objects.
35+
A lightweight convenience wrapper for using CF attributes on xarray objects.
3636

3737
For example you can use ``.cf.mean("latitude")`` instead of ``.mean("lat")`` if appropriate attributes are set! This allows you to write code that does not require knowledge of specific dimension or coordinate names particular to a dataset.
3838

cf_xarray/data/cf-standard-name-table.xml

Lines changed: 5083 additions & 5083 deletions
Large diffs are not rendered by default.

cf_xarray/options.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ class set_options:
3232
3333
>>> import numpy as np
3434
>>> import xarray as xr
35-
>>> my_custom_criteria = { 'ssh': {'name': 'elev$'} }
35+
>>> my_custom_criteria = {"ssh": {"name": "elev$"}}
3636
>>> ds = xr.Dataset({"elev": np.arange(1000)})
3737
>>> with cf_xarray.set_options(custom_criteria=my_custom_criteria):
38-
... xr.testing.assert_identical(ds['elev'], ds.cf['ssh'])
38+
... xr.testing.assert_identical(ds["elev"], ds.cf["ssh"])
39+
...
3940
4041
Or to set global options:
4142
4243
>>> cf_xarray.set_options(custom_criteria=my_custom_criteria)
43-
>>> xr.testing.assert_identical(ds['elev'], ds.cf['ssh'])
44+
>>> xr.testing.assert_identical(ds["elev"], ds.cf["ssh"])
4445
"""
4546

4647
def __init__(self, **kwargs):

doc/bounds.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Bounds Variables
66

77
See
8+
89
1. {py:attr}`Dataset.cf.bounds`,
910
1. {py:func}`Dataset.cf.add_bounds`,
1011
1. {py:func}`cf_xarray.bounds_to_vertices`,

doc/coding.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ kernelspec:
66
display_name: Python 3
77
name: python3
88
---
9+
910
```{eval-rst}
1011
.. currentmodule:: cf_xarray
1112
```
13+
1214
```{code-cell}
1315
---
1416
tags: [remove-cell]
@@ -20,22 +22,22 @@ import xarray as xr
2022
xr.set_options(display_expand_data=False)
2123
```
2224

23-
2425
# Encoding and decoding
2526

26-
`cf_xarray` aims to support encoding and decoding variables using CF conventions not yet implemented by Xarray.
27+
`cf_xarray` aims to support encoding and decoding variables using CF conventions not yet implemented by Xarray.
2728

2829
## Compression by gathering
2930

30-
The ["compression by gathering"](http://cfconventions.org/Data/cf-conventions/cf-conventions-1.8/cf-conventions.html#compression-by-gathering)
31+
The ["compression by gathering"](http://cfconventions.org/Data/cf-conventions/cf-conventions-1.8/cf-conventions.html#compression-by-gathering)
3132
convention could be used for either {py:class}`pandas.MultiIndex` objects or `pydata/sparse` arrays.
3233

3334
### MultiIndex
3435

35-
``cf_xarray`` provides {py:func}`encode_multi_index_as_compress` and {py:func}`decode_compress_to_multi_index` to encode MultiIndex-ed
36-
dimensions using "compression by gethering".
36+
`cf_xarray` provides {py:func}`encode_multi_index_as_compress` and {py:func}`decode_compress_to_multi_index` to encode MultiIndex-ed
37+
dimensions using "compression by gethering".
3738

3839
Here's a test dataset
40+
3941
```{code-cell}
4042
ds = xr.Dataset(
4143
{"landsoilt": ("landpoint", np.random.randn(4), {"foo": "bar"})},
@@ -47,20 +49,24 @@ ds = xr.Dataset(
4749
)
4850
ds
4951
```
52+
5053
First encode (note the `"compress"` attribute on the `landpoint` variable)
54+
5155
```{code-cell}
5256
encoded = cfxr.encode_multi_index_as_compress(ds, "landpoint")
5357
encoded
5458
```
5559

5660
At this point, we can write `encoded` to a CF-compliant dataset using {py:func}`xarray.Dataset.to_netcdf` for example.
5761
After reading that file, decode using
62+
5863
```{code-cell}
5964
decoded = cfxr.decode_compress_to_multi_index(encoded, "landpoint")
6065
decoded
6166
```
6267

6368
We roundtrip perfectly
69+
6470
```{code-cell}
6571
ds.identical(decoded)
6672
```

doc/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# complexity documentation build configuration file, created by
42
# sphinx-quickstart on Tue Jul 9 22:26:36 2013.
53
#

doc/contributing.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,3 @@ Primarily for developer reference. Some of these could become public API if nece
7070
~accessor._get_indexes
7171
~accessor._get_measure
7272
~accessor._get_with_standard_name
73-

doc/coord_axes.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ kernelspec:
66
display_name: Python 3
77
name: python3
88
---
9+
910
```{eval-rst}
1011
.. currentmodule:: xarray
1112
```
13+
1214
```{code-cell}
1315
---
1416
tags: [remove-cell]
@@ -19,9 +21,10 @@ xr.set_options(display_expand_data=False)
1921

2022
# Axes and Coordinates
2123

22-
One powerful feature of ``cf_xarray`` is the ability to refer to named dimensions by standard `axis` or `coordinate` names in Dataset or DataArray methods.
24+
One powerful feature of `cf_xarray` is the ability to refer to named dimensions by standard `axis` or `coordinate` names in Dataset or DataArray methods.
2325

2426
For example, one can call `ds.cf.mean("latitude")` instead of `ds.mean("lat")`
27+
2528
```{code-cell}
2629
from cf_xarray.datasets import airds
2730
@@ -34,24 +37,26 @@ Most xarray methods are wrapped by cf-xarray. Simply access them as `DataArray.c
3437
```
3538

3639
## Coordinate Names
37-
How does this work? `cf_xarray` has an internal table of criteria (mostly copied from MetPy) that lets it identify specific coordinate names `"latitude", "longitude", "vertical", "time"`.
3840

41+
How does this work? `cf_xarray` has an internal table of criteria (mostly copied from MetPy) that lets it identify specific coordinate names `"latitude", "longitude", "vertical", "time"`.
3942

4043
```{tip}
4144
See {ref}`custom_criteria` to find out how to define your own custom criteria.
4245
```
4346

44-
This table lists these internal criteria
47+
This table lists these internal criteria
48+
4549
```{eval-rst}
4650
.. csv-table::
4751
:file: _build/csv/coords_criteria.csv
4852
:header-rows: 1
4953
:stub-columns: 1
5054
```
51-
Any DataArray that has `standard_name: "latitude"` or `_CoordinateAxisType: "Lat"` or `"units": "degrees_north"` in its `attrs` will be identified as the `"latitude"` variable by cf-xarray. Similarly for other coordinate names.
5255

56+
Any DataArray that has `standard_name: "latitude"` or `_CoordinateAxisType: "Lat"` or `"units": "degrees_north"` in its `attrs` will be identified as the `"latitude"` variable by cf-xarray. Similarly for other coordinate names.
5357

5458
## Axis Names
59+
5560
Similar criteria exist for the concept of "axes".
5661

5762
```{eval-rst}
@@ -62,7 +67,9 @@ Similar criteria exist for the concept of "axes".
6267
```
6368

6469
## `.axes` and `.coordinates` properties
70+
6571
Alternatively use the special properties {py:attr}`DataArray.cf.axes` or {py:attr}`DataArray.cf.coordinates` to access the variable names. These properties return dictionaries that map "CF names" to a list of variable names. Note that a list is always returned even if only one variable name matches the name `"latitude"` (for example).
72+
6673
```{code-cell}
6774
airds.cf.axes
6875
```
@@ -78,22 +85,25 @@ TODO describe latitude vs Y; longitude vs X; vertical vs Z
7885
## Checking presence of axis or coordinate
7986

8087
Note that a given "CF name" is only present if there is at least one variable that can be identified with that name. The `airds` dataset has no `"vertical"` coordinate or `"Z"` axis, so those keys are not present. So to check whether a `"vertical"` coordinate or `"Z"` axis is present, one can
88+
8189
```{code-cell}
8290
"Z" in airds.cf.axes
8391
```
92+
8493
```{code-cell}
8594
"vertical" in airds.cf.coordinates
8695
```
8796

8897
Or one can check the dataset as a whole:
98+
8999
```{code-cell}
90100
"Z" in airds.cf
91101
```
92102

93-
94-
95103
## Using the repr
104+
96105
It is always useful to check the variables identified by cf-xarray using the `repr`
106+
97107
```{code-cell}
98108
airds.cf
99109
```

0 commit comments

Comments
 (0)