Skip to content

Commit a3cc075

Browse files
committed
Merge branch 'main' into get_slice_bound-kind
2 parents f8607aa + 214bbe0 commit a3cc075

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+752
-411
lines changed

.github/workflows/ci-additional.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ jobs:
102102
$PYTEST_EXTRA_FLAGS
103103
104104
- name: Upload code coverage to Codecov
105-
uses: codecov/codecov-action@v2.0.3
105+
uses: codecov/codecov-action@v2.1.0
106106
with:
107107
file: ./coverage.xml
108108
flags: unittests,${{ matrix.env }}

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
path: pytest.xml
101101

102102
- name: Upload code coverage to Codecov
103-
uses: codecov/codecov-action@v2.0.3
103+
uses: codecov/codecov-action@v2.1.0
104104
with:
105105
file: ./coverage.xml
106106
flags: unittests

.pre-commit-config.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
- id: isort
1414
# https://github.com/python/black#version-control-integration
1515
- repo: https://github.com/psf/black
16-
rev: 21.7b0
16+
rev: 21.9b0
1717
hooks:
1818
- id: black
1919
- repo: https://github.com/keewis/blackdoc
@@ -30,20 +30,21 @@ repos:
3030
# - id: velin
3131
# args: ["--write", "--compact"]
3232
- repo: https://github.com/pre-commit/mirrors-mypy
33-
rev: v0.910
33+
rev: v0.910-1
3434
hooks:
3535
- id: mypy
36-
# Copied from setup.cfg
37-
exclude: "properties|asv_bench"
36+
# `properies` & `asv_bench` are copied from setup.cfg.
37+
# `_typed_ops.py` is added since otherwise mypy will complain (but notably only in pre-commit)
38+
exclude: "properties|asv_bench|_typed_ops.py"
3839
additional_dependencies: [
3940
# Type stubs
4041
types-python-dateutil,
4142
types-pkg_resources,
4243
types-PyYAML,
4344
types-pytz,
45+
typing-extensions==3.10.0.0,
4446
# Dependencies that are typed
4547
numpy,
46-
typing-extensions==3.10.0.0,
4748
]
4849
# run this occasionally, ref discussion https://github.com/pydata/xarray/pull/3194
4950
# - repo: https://github.com/asottile/pyupgrade

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ to support our efforts.
105105
History
106106
-------
107107

108-
xarray is an evolution of an internal tool developed at `The Climate
108+
Xarray is an evolution of an internal tool developed at `The Climate
109109
Corporation`__. It was originally written by Climate Corp researchers Stephan
110110
Hoyer, Alex Kleeman and Eugene Brevdo and was released as open source in
111111
May 2014. The project was renamed from "xray" in January 2016. Xarray became a
@@ -131,16 +131,16 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131131
See the License for the specific language governing permissions and
132132
limitations under the License.
133133

134-
xarray bundles portions of pandas, NumPy and Seaborn, all of which are available
134+
Xarray bundles portions of pandas, NumPy and Seaborn, all of which are available
135135
under a "3-clause BSD" license:
136136
- pandas: setup.py, xarray/util/print_versions.py
137137
- NumPy: xarray/core/npcompat.py
138138
- Seaborn: _determine_cmap_params in xarray/core/plot/utils.py
139139

140-
xarray also bundles portions of CPython, which is available under the "Python
140+
Xarray also bundles portions of CPython, which is available under the "Python
141141
Software Foundation License" in xarray/core/pycompat.py.
142142

143-
xarray uses icons from the icomoon package (free version), which is
143+
Xarray uses icons from the icomoon package (free version), which is
144144
available under the "CC BY 4.0" license.
145145

146146
The full text of these licenses are included in the licenses directory.

asv_bench/benchmarks/groupby.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import numpy as np
2+
3+
import xarray as xr
4+
5+
from . import parameterized, requires_dask
6+
7+
8+
class GroupBy:
9+
def setup(self, *args, **kwargs):
10+
self.ds = xr.Dataset(
11+
{
12+
"a": xr.DataArray(np.r_[np.arange(500.0), np.arange(500.0)]),
13+
"b": xr.DataArray(np.arange(1000.0)),
14+
}
15+
)
16+
17+
@parameterized(["method"], [("sum", "mean")])
18+
def time_agg(self, method):
19+
return getattr(self.ds.groupby("a"), method)()
20+
21+
22+
class GroupByDask(GroupBy):
23+
def setup(self, *args, **kwargs):
24+
requires_dask()
25+
super().setup(**kwargs)
26+
self.ds = self.ds.chunk({"dim_0": 50})
27+
28+
29+
class GroupByDataFrame(GroupBy):
30+
def setup(self, *args, **kwargs):
31+
super().setup(**kwargs)
32+
self.ds = self.ds.to_dataframe()
33+
34+
35+
class GroupByDaskDataFrame(GroupBy):
36+
def setup(self, *args, **kwargs):
37+
requires_dask()
38+
super().setup(**kwargs)
39+
self.ds = self.ds.chunk({"dim_0": 50}).to_dataframe()

ci/requirements/doc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies:
2323
- pooch
2424
- pip
2525
- pydata-sphinx-theme>=0.4.3
26+
- pyproj
2627
- rasterio>=1.1
2728
- seaborn
2829
- setuptools

doc/api.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Top-level functions
3535
map_blocks
3636
show_versions
3737
set_options
38+
get_options
3839
unify_chunks
3940

4041
Dataset
@@ -598,8 +599,8 @@ Universal functions
598599

599600
.. warning::
600601

601-
With recent versions of numpy, dask and xarray, NumPy ufuncs are now
602-
supported directly on all xarray and dask objects. This obviates the need
602+
With recent versions of NumPy, Dask and xarray, NumPy ufuncs are now
603+
supported directly on all xarray and Dask objects. This obviates the need
603604
for the ``xarray.ufuncs`` module, which should not be used for new code
604605
unless compatibility with versions of NumPy prior to v1.13 is
605606
required. They will be removed once support for NumPy prior to

doc/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@
260260
ogp_image = "https://xarray.pydata.org/en/stable/_static/dataset-diagram-logo.png"
261261
ogp_custom_meta_tags = [
262262
'<meta name="twitter:card" content="summary_large_image" />',
263-
'<meta property="twitter:site" content="@xarray_dev />',
264-
'<meta name="image" property="og:image" content="https://xarray.pydata.org/en/stable/_static/dataset-diagram-logo.png">',
263+
'<meta property="twitter:site" content="@xarray_dev" />',
264+
'<meta name="image" property="og:image" content="https://xarray.pydata.org/en/stable/_static/dataset-diagram-logo.png" />',
265265
]
266266

267267
# Redirects for pages that were moved to new locations

doc/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ Some other important things to know about the docs:
257257
tutorial-like overviews per topic together with some other information
258258
(what's new, installation, etc).
259259

260-
- The docstrings follow the **Numpy Docstring Standard**, which is used widely
260+
- The docstrings follow the **NumPy Docstring Standard**, which is used widely
261261
in the Scientific Python community. This standard specifies the format of
262262
the different sections of the docstring. See `this document
263263
<https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard>`_

doc/ecosystem.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Geosciences
5050
Machine Learning
5151
~~~~~~~~~~~~~~~~
5252
- `ArviZ <https://arviz-devs.github.io/arviz/>`_: Exploratory analysis of Bayesian models, built on top of xarray.
53+
- `Darts <https://github.com/unit8co/darts/>`_: User-friendly modern machine learning for time series in Python.
5354
- `Elm <https://ensemble-learning-models.readthedocs.io>`_: Parallel machine learning on xarray data structures
5455
- `sklearn-xarray (1) <https://phausamann.github.io/sklearn-xarray>`_: Combines scikit-learn and xarray (1).
5556
- `sklearn-xarray (2) <https://sklearn-xarray.readthedocs.io/en/latest/>`_: Combines scikit-learn and xarray (2).

doc/examples/ERA5-GRIB-example.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"cell_type": "markdown",
1212
"metadata": {},
1313
"source": [
14-
"GRIB format is commonly used to disseminate atmospheric model data. With Xarray and the cfgrib engine, GRIB data can easily be analyzed and visualized."
14+
"GRIB format is commonly used to disseminate atmospheric model data. With xarray and the cfgrib engine, GRIB data can easily be analyzed and visualized."
1515
]
1616
},
1717
{

doc/examples/multidimensional-coords.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
"source": [
185185
"The resulting coordinate for the `groupby_bins` operation got the `_bins` suffix appended: `xc_bins`. This help us distinguish it from the original multidimensional variable `xc`.\n",
186186
"\n",
187-
"**Note**: This group-by-latitude approach does not take into account the finite-size geometry of grid cells. It simply bins each value according to the coordinates at the cell center. Xarray has no understanding of grid cells and their geometry. More precise geographic regridding for Xarray data is available via the [xesmf](https://xesmf.readthedocs.io) package."
187+
"**Note**: This group-by-latitude approach does not take into account the finite-size geometry of grid cells. It simply bins each value according to the coordinates at the cell center. Xarray has no understanding of grid cells and their geometry. More precise geographic regridding for xarray data is available via the [xesmf](https://xesmf.readthedocs.io) package."
188188
]
189189
},
190190
{

doc/examples/visualization_gallery.ipynb

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"# Visualization Gallery\n",
88
"\n",
9-
"This notebook shows common visualization issues encountered in Xarray."
9+
"This notebook shows common visualization issues encountered in xarray."
1010
]
1111
},
1212
{
@@ -191,7 +191,10 @@
191191
},
192192
{
193193
"cell_type": "markdown",
194-
"metadata": {},
194+
"metadata": {
195+
"jp-MarkdownHeadingCollapsed": true,
196+
"tags": []
197+
},
195198
"source": [
196199
"## `imshow()` and rasterio map projections\n",
197200
"\n",
@@ -213,7 +216,7 @@
213216
"\n",
214217
"# The data is in UTM projection. We have to set it manually until\n",
215218
"# https://github.com/SciTools/cartopy/issues/813 is implemented\n",
216-
"crs = ccrs.UTM('18N')\n",
219+
"crs = ccrs.UTM('18')\n",
217220
"\n",
218221
"# Plot on a map\n",
219222
"ax = plt.subplot(projection=crs)\n",
@@ -242,20 +245,14 @@
242245
"metadata": {},
243246
"outputs": [],
244247
"source": [
245-
"from rasterio.warp import transform\n",
248+
"from pyproj import Transformer\n",
246249
"import numpy as np\n",
247250
"\n",
248251
"da = xr.tutorial.open_rasterio(\"RGB.byte\")\n",
249252
"\n",
250-
"# Compute the lon/lat coordinates with rasterio.warp.transform\n",
251-
"ny, nx = len(da['y']), len(da['x'])\n",
252253
"x, y = np.meshgrid(da['x'], da['y'])\n",
253-
"\n",
254-
"# Rasterio works with 1D arrays\n",
255-
"lon, lat = transform(da.crs, {'init': 'EPSG:4326'},\n",
256-
" x.flatten(), y.flatten())\n",
257-
"lon = np.asarray(lon).reshape((ny, nx))\n",
258-
"lat = np.asarray(lat).reshape((ny, nx))\n",
254+
"transformer = Transformer.from_crs(da.crs, \"EPSG:4326\", always_xy=True)\n",
255+
"lon, lat = transformer.transform(x, y)\n",
259256
"da.coords['lon'] = (('y', 'x'), lon)\n",
260257
"da.coords['lat'] = (('y', 'x'), lat)\n",
261258
"\n",
@@ -265,14 +262,14 @@
265262
"# Plot on a map\n",
266263
"ax = plt.subplot(projection=ccrs.PlateCarree())\n",
267264
"greyscale.plot(ax=ax, x='lon', y='lat', transform=ccrs.PlateCarree(),\n",
268-
" cmap='Greys_r', add_colorbar=False)\n",
265+
" cmap='Greys_r', shading=\"auto\",add_colorbar=False)\n",
269266
"ax.coastlines('10m', color='r')"
270267
]
271268
}
272269
],
273270
"metadata": {
274271
"kernelspec": {
275-
"display_name": "Python 3",
272+
"display_name": "Python 3 (ipykernel)",
276273
"language": "python",
277274
"name": "python3"
278275
},
@@ -286,7 +283,7 @@
286283
"name": "python",
287284
"nbconvert_exporter": "python",
288285
"pygments_lexer": "ipython3",
289-
"version": "3.7.3"
286+
"version": "3.9.7"
290287
}
291288
},
292289
"nbformat": 4,

doc/gallery/plot_rasterio.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,17 @@
1818
import cartopy.crs as ccrs
1919
import matplotlib.pyplot as plt
2020
import numpy as np
21-
from rasterio.warp import transform
21+
from pyproj import Transformer
2222

2323
import xarray as xr
2424

2525
# Read the data
2626
url = "https://github.com/mapbox/rasterio/raw/master/tests/data/RGB.byte.tif"
2727
da = xr.open_rasterio(url)
2828

29-
# Compute the lon/lat coordinates with rasterio.warp.transform
30-
ny, nx = len(da["y"]), len(da["x"])
31-
x, y = np.meshgrid(da["x"], da["y"])
32-
33-
# Rasterio works with 1D arrays
34-
lon, lat = transform(da.crs, {"init": "EPSG:4326"}, x.flatten(), y.flatten())
35-
lon = np.asarray(lon).reshape((ny, nx))
36-
lat = np.asarray(lat).reshape((ny, nx))
29+
# Compute the lon/lat coordinates with pyproj
30+
transformer = Transformer.from_crs(da.crs, "EPSG:4326", always_xy=True)
31+
lon, lat = transformer.transform(*np.meshgrid(da["x"], da["y"]))
3732
da.coords["lon"] = (("y", "x"), lon)
3833
da.coords["lat"] = (("y", "x"), lat)
3934

doc/getting-started-guide/faq.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ rows) shouldn't really matter. For example, the images of a movie can be
5555
natively represented as an array with four dimensions: time, row, column and
5656
color.
5757

58-
Pandas has historically supported N-dimensional panels, but deprecated them in
59-
version 0.20 in favor of Xarray data structures. There are now built-in methods
60-
on both sides to convert between pandas and Xarray, allowing for more focused
58+
pandas has historically supported N-dimensional panels, but deprecated them in
59+
version 0.20 in favor of xarray data structures. There are now built-in methods
60+
on both sides to convert between pandas and xarray, allowing for more focused
6161
development effort. Xarray objects have a much richer model of dimensionality -
6262
if you were using Panels:
6363

@@ -72,8 +72,8 @@ if you were using Panels:
7272
In contrast, this sort of data structure fits very naturally in an
7373
xarray ``Dataset``.
7474

75-
You can :ref:`read about switching from Panels to Xarray here <panel transition>`.
76-
Pandas gets a lot of things right, but many science, engineering and complex
75+
You can :ref:`read about switching from Panels to xarray here <panel transition>`.
76+
pandas gets a lot of things right, but many science, engineering and complex
7777
analytics use cases need fully multi-dimensional data structures.
7878

7979
How do xarray data structures differ from those found in pandas?
@@ -92,7 +92,7 @@ of the "time" dimension. You never need to reshape arrays (e.g., with
9292
Why don't aggregations return Python scalars?
9393
---------------------------------------------
9494

95-
xarray tries hard to be self-consistent: operations on a ``DataArray`` (resp.
95+
Xarray tries hard to be self-consistent: operations on a ``DataArray`` (resp.
9696
``Dataset``) return another ``DataArray`` (resp. ``Dataset``) object. In
9797
particular, operations returning scalar values (e.g. indexing or aggregations
9898
like ``mean`` or ``sum`` applied to all axes) will also return xarray objects.
@@ -152,7 +152,7 @@ What other netCDF related Python libraries should I know about?
152152

153153
`netCDF4-python`__ provides a lower level interface for working with
154154
netCDF and OpenDAP datasets in Python. We use netCDF4-python internally in
155-
xarray, and have contributed a number of improvements and fixes upstream. xarray
155+
xarray, and have contributed a number of improvements and fixes upstream. Xarray
156156
does not yet support all of netCDF4-python's features, such as modifying files
157157
on-disk.
158158

@@ -161,7 +161,7 @@ __ https://github.com/Unidata/netcdf4-python
161161
Iris_ (supported by the UK Met office) provides similar tools for in-
162162
memory manipulation of labeled arrays, aimed specifically at weather and
163163
climate data needs. Indeed, the Iris :py:class:`~iris.cube.Cube` was direct
164-
inspiration for xarray's :py:class:`~xarray.DataArray`. xarray and Iris take very
164+
inspiration for xarray's :py:class:`~xarray.DataArray`. Xarray and Iris take very
165165
different approaches to handling metadata: Iris strictly interprets
166166
`CF conventions`_. Iris particularly shines at mapping, thanks to its
167167
integration with Cartopy_.

doc/getting-started-guide/installing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Alternative data containers
8787

8888
Minimum dependency versions
8989
---------------------------
90-
xarray adopts a rolling policy regarding the minimum supported version of its
90+
Xarray adopts a rolling policy regarding the minimum supported version of its
9191
dependencies:
9292

9393
- **Python:** 24 months
@@ -110,7 +110,7 @@ You can see the actual minimum tested versions:
110110
Instructions
111111
------------
112112

113-
xarray itself is a pure Python package, but its dependencies are not. The
113+
Xarray itself is a pure Python package, but its dependencies are not. The
114114
easiest way to get everything installed is to use conda_. To install xarray
115115
with its recommended dependencies using the conda command line tool::
116116

doc/getting-started-guide/quick-overview.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Here are the key properties for a ``DataArray``:
4646
Indexing
4747
--------
4848

49-
xarray supports four kinds of indexing. Since we have assigned coordinate labels to the x dimension we can use label-based indexing along that dimension just like pandas. The four examples below all yield the same result (the value at `x=10`) but at varying levels of convenience and intuitiveness.
49+
Xarray supports four kinds of indexing. Since we have assigned coordinate labels to the x dimension we can use label-based indexing along that dimension just like pandas. The four examples below all yield the same result (the value at `x=10`) but at varying levels of convenience and intuitiveness.
5050

5151
.. ipython:: python
5252
@@ -133,7 +133,7 @@ For more, see :ref:`comput`.
133133
GroupBy
134134
-------
135135

136-
xarray supports grouped operations using a very similar API to pandas (see :ref:`groupby`):
136+
Xarray supports grouped operations using a very similar API to pandas (see :ref:`groupby`):
137137

138138
.. ipython:: python
139139
@@ -225,4 +225,4 @@ You can directly read and write xarray objects to disk using :py:meth:`~xarray.D
225225
os.remove("example.nc")
226226
227227
228-
It is common for datasets to be distributed across multiple files (commonly one file per timestep). xarray supports this use-case by providing the :py:meth:`~xarray.open_mfdataset` and the :py:meth:`~xarray.save_mfdataset` methods. For more, see :ref:`io`.
228+
It is common for datasets to be distributed across multiple files (commonly one file per timestep). Xarray supports this use-case by providing the :py:meth:`~xarray.open_mfdataset` and the :py:meth:`~xarray.save_mfdataset` methods. For more, see :ref:`io`.

0 commit comments

Comments
 (0)