Skip to content

Commit

Permalink
Merge branch 'main' into typedalign
Browse files Browse the repository at this point in the history
  • Loading branch information
headtr1ck committed Oct 5, 2023
2 parents be3b256 + e09609c commit dc89546
Show file tree
Hide file tree
Showing 41 changed files with 2,333 additions and 1,625 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ repos:
files: ^xarray/
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.287'
rev: 'v0.0.292'
hooks:
- id: ruff
args: ["--fix"]
# https://github.com/python/black#version-control-integration
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black-jupyter
- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
hooks:
- id: blackdoc
exclude: "generate_aggregations.py"
additional_dependencies: ["black==23.7.0"]
additional_dependencies: ["black==23.9.1"]
- id: blackdoc-autoupdate-black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
Expand Down
1 change: 1 addition & 0 deletions doc/ecosystem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Geosciences
harmonic wind analysis in Python.
- `wradlib <https://wradlib.org/>`_: An Open Source Library for Weather Radar Data Processing.
- `wrf-python <https://wrf-python.readthedocs.io/>`_: A collection of diagnostic and interpolation routines for use with output of the Weather Research and Forecasting (WRF-ARW) Model.
- `xarray-regrid <https://github.com/EXCITED-CO2/xarray-regrid>`_: xarray extension for regridding rectilinear data.
- `xarray-simlab <https://xarray-simlab.readthedocs.io>`_: xarray extension for computer model simulations.
- `xarray-spatial <https://xarray-spatial.org/>`_: Numba-accelerated raster-based spatial processing tools (NDVI, curvature, zonal-statistics, proximity, hillshading, viewshed, etc.)
- `xarray-topo <https://xarray-topo.readthedocs.io/>`_: xarray extension for topographic analysis and modelling.
Expand Down
84 changes: 72 additions & 12 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,76 @@ What's New
np.random.seed(123456)
.. _whats-new.2023.08.1:
.. _whats-new.2023.09.1:

v2023.08.1 (unreleased)
v2023.09.1 (unreleased)
-----------------------

New Features
~~~~~~~~~~~~

- :py:meth:`DataArray.where` & :py:meth:`Dataset.where` accept a callable for
the ``other`` parameter, passing the object as the first argument. Previously,
this was only valid for the ``cond`` parameter. (:issue:`8255`)
By `Maximilian Roos <https://github.com/max-sixty>`_.

Breaking changes
~~~~~~~~~~~~~~~~

- :py:meth:`Dataset.to_zarr` & :py:meth:`DataArray.to_zarr` require keyword
arguments after the initial 7 positional arguments.
By `Maximilian Roos <https://github.com/max-sixty>`_.


Deprecations
~~~~~~~~~~~~


Bug fixes
~~~~~~~~~
- :py:meth:`DataArray.rename` & :py:meth:`Dataset.rename` would emit a warning
when the operation was a no-op. (:issue:`8266`)
By `Simon Hansen <https://github.com/hoxbro>`_.


Documentation
~~~~~~~~~~~~~

- Added xarray-regrid to the list of xarray related projects (:pull:`8272`).
By `Bart Schilperoort <https://github.com/BSchilperoort>`_.


Internal Changes
~~~~~~~~~~~~~~~~


.. _whats-new.2023.09.0:

v2023.09.0 (Sep 26, 2023)
-------------------------

This release continues work on the new :py:class:`xarray.Coordinates` object, allows to provide `preferred_chunks` when
reading from netcdf files, enables :py:func:`xarray.apply_ufunc` to handle missing core dimensions and fixes several bugs.

Thanks to the 24 contributors to this release: Alexander Fischer, Amrest Chinkamol, Benoit Bovy, Darsh Ranjan, Deepak Cherian,
Gianfranco Costamagna, Gregorio L. Trevisan, Illviljan, Joe Hamman, JR, Justus Magin, Kai Mühlbauer, Kian-Meng Ang, Kyle Sunden,
Martin Raspaud, Mathias Hauser, Mattia Almansi, Maximilian Roos, András Gunyhó, Michael Niklas, Richard Kleijn, Riulinchen,
Tom Nicholas and Wiktor Kraśnicki.

We welcome the following new contributors to Xarray!: Alexander Fischer, Amrest Chinkamol, Darsh Ranjan, Gianfranco Costamagna, Gregorio L. Trevisan,
Kian-Meng Ang, Riulinchen and Wiktor Kraśnicki.

New Features
~~~~~~~~~~~~

- Added the :py:meth:`Coordinates.assign` method that can be used to combine
different collections of coordinates prior to assign them to a Dataset or
DataArray (:pull:`8102`) at once.
By `Benoît Bovy <https://github.com/benbovy>`_.
- Provide `preferred_chunks` for data read from netcdf files (:issue:`1440`, :pull:`7948`).
By `Martin Raspaud <https://github.com/mraspaud>`_.
- Improved static typing of reduction methods (:pull:`6746`).
By `Richard Kleijn <https://github.com/rhkleijn>`_.
- Added `on_missing_core_dims` to :py:meth:`apply_ufunc` to allow for copying or
dropping a :py:class:`Dataset`'s variables with missing core dimensions.
(:pull:`8138`)
dropping a :py:class:`Dataset`'s variables with missing core dimensions (:pull:`8138`).
By `Maximilian Roos <https://github.com/max-sixty>`_.

Breaking changes
Expand Down Expand Up @@ -61,6 +112,8 @@ Deprecations
Bug fixes
~~~~~~~~~

- Improved static typing of reduction methods (:pull:`6746`).
By `Richard Kleijn <https://github.com/rhkleijn>`_.
- Fix bug where empty attrs would generate inconsistent tokens (:issue:`6970`, :pull:`8101`).
By `Mattia Almansi <https://github.com/malmans2>`_.
- Improved handling of multi-coordinate indexes when updating coordinates, including bug fixes
Expand All @@ -71,8 +124,8 @@ Bug fixes
:pull:`8104`).
By `Benoît Bovy <https://github.com/benbovy>`_.
- Fix bug where :py:class:`DataArray` instances on the right-hand side
of :py:meth:`DataArray.__setitem__` lose dimension names.
(:issue:`7030`, :pull:`8067`) By `Darsh Ranjan <https://github.com/dranjan>`_.
of :py:meth:`DataArray.__setitem__` lose dimension names (:issue:`7030`, :pull:`8067`).
By `Darsh Ranjan <https://github.com/dranjan>`_.
- Return ``float64`` in presence of ``NaT`` in :py:class:`~core.accessor_dt.DatetimeAccessor` and
special case ``NaT`` handling in :py:meth:`~core.accessor_dt.DatetimeAccessor.isocalendar`
(:issue:`7928`, :pull:`8084`).
Expand All @@ -83,19 +136,27 @@ Bug fixes
- Calling plot with kwargs ``col``, ``row`` or ``hue`` no longer squeezes dimensions passed via these arguments
(:issue:`7552`, :pull:`8174`).
By `Wiktor Kraśnicki <https://github.com/wkrasnicki>`_.
- Fixed a bug where casting from ``float`` to ``int64`` (undefined for ``NaN``) led to varying
issues (:issue:`7817`, :issue:`7942`, :issue:`7790`, :issue:`6191`, :issue:`7096`,
- Fixed a bug where casting from ``float`` to ``int64`` (undefined for ``NaN``) led to varying issues (:issue:`7817`, :issue:`7942`, :issue:`7790`, :issue:`6191`, :issue:`7096`,
:issue:`1064`, :pull:`7827`).
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
- Fixed a bug where inaccurate ``coordinates`` silently failed to decode variable (:issue:`1809`, :pull:`8195`).
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_
- ``.rolling_exp`` functions no longer mistakenly lose non-dimensioned coords
(:issue:`6528`, :pull:`8114`)
(:issue:`6528`, :pull:`8114`).
By `Maximilian Roos <https://github.com/max-sixty>`_.
- In the event that user-provided datetime64/timedelta64 units and integer dtype encoding parameters conflict with each other, override the units to preserve an integer dtype for most faithful serialization to disk (:issue:`1064`, :pull:`8201`).
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
- Static typing of dunder ops methods (like :py:meth:`DataArray.__eq__`) has been fixed.
Remaining issues are upstream problems (:issue:`7780`, :pull:`8204`).
By `Michael Niklas <https://github.com/headtr1ck>`_.
- Fix type annotation for ``center`` argument of plotting methods (like :py:meth:`xarray.plot.dataarray_plot.pcolormesh`) (:pull:`8261`).
By `Pieter Eendebak <https://github.com/eendebakpt>`_.

Documentation
~~~~~~~~~~~~~

- Make documentation of :py:meth:`DataArray.where` clearer (:issue:`7767`, :pull:`7955`).
By `Riulinchen <https://github.com/Riulinchen>`_.

Internal Changes
~~~~~~~~~~~~~~~~
Expand All @@ -111,7 +172,6 @@ Internal Changes
- Test range of fill_value's in test_interpolate_pd_compat (:issue:`8146`, :pull:`8189`).
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.


.. _whats-new.2023.08.0:

v2023.08.0 (Aug 18, 2023)
Expand Down
85 changes: 79 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ module = [
"cftime.*",
"cubed.*",
"cupy.*",
"dask.types.*",
"fsspec.*",
"h5netcdf.*",
"h5py.*",
Expand All @@ -119,13 +120,83 @@ module = [
]

# Gradually we want to add more modules to this list, ratcheting up our total
# coverage. Once a module is here, functions require annotations in order to
# pass mypy. It would be especially useful to have tests here, because without
# annotating test functions, we don't have a great way of testing our type
# annotations — even with just `-> None` is sufficient for mypy to check them.
# coverage. Once a module is here, functions are checked by mypy regardless of
# whether they have type annotations. It would be especially useful to have test
# files listed here, because without them being checked, we don't have a great
# way of testing our annotations.
[[tool.mypy.overrides]]
check_untyped_defs = true
module = [
"xarray.core.accessor_dt",
"xarray.core.accessor_str",
"xarray.core.alignment",
"xarray.core.computation",
"xarray.core.rolling_exp",
"xarray.indexes.*",
"xarray.tests.*",
]
# This then excludes some modules from the above list. (So ideally we remove
# from here in time...)
[[tool.mypy.overrides]]
check_untyped_defs = false
module = [
"xarray.tests.test_coarsen",
"xarray.tests.test_coding_times",
"xarray.tests.test_combine",
"xarray.tests.test_computation",
"xarray.tests.test_concat",
"xarray.tests.test_coordinates",
"xarray.tests.test_dask",
"xarray.tests.test_dataarray",
"xarray.tests.test_duck_array_ops",
"xarray.tests.test_groupby",
"xarray.tests.test_indexing",
"xarray.tests.test_merge",
"xarray.tests.test_missing",
"xarray.tests.test_parallelcompat",
"xarray.tests.test_plot",
"xarray.tests.test_sparse",
"xarray.tests.test_ufuncs",
"xarray.tests.test_units",
"xarray.tests.test_utils",
"xarray.tests.test_variable",
"xarray.tests.test_weighted",
]

# Use strict = true whenever namedarray has become standalone. In the meantime
# don't forget to add all new files related to namedarray here:
# ref: https://mypy.readthedocs.io/en/stable/existing_code.html#introduce-stricter-options
[[tool.mypy.overrides]]
# Start off with these
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true

# Getting these passing should be easy
strict_equality = true
strict_concatenate = true

# Strongly recommend enabling this one as soon as you can
check_untyped_defs = true

# These shouldn't be too much additional work, but may be tricky to
# get passing if you use a lot of untyped libraries
disallow_subclassing_any = true
disallow_untyped_decorators = true
disallow_any_generics = true

# These next few are various gradations of forcing use of type annotations
disallow_untyped_calls = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
module = ["xarray.core.rolling_exp"]

# This one isn't too hard to get passing, but return on investment is lower
no_implicit_reexport = true

# This one can be tricky to get passing if you use a lot of untyped libraries
warn_return_any = true

module = ["xarray.namedarray.*", "xarray.tests.test_namedarray"]

[tool.ruff]
builtins = ["ellipsis"]
Expand Down Expand Up @@ -155,7 +226,9 @@ select = [
known-first-party = ["xarray"]

[tool.pytest.ini_options]
addopts = '--strict-markers'
addopts = ["--strict-config", "--strict-markers"]
log_cli_level = "INFO"
minversion = "7"
filterwarnings = [
"ignore:Using a non-tuple sequence for multidimensional indexing is deprecated:FutureWarning",
]
Expand Down
8 changes: 8 additions & 0 deletions xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,9 @@ def open_dataset(
as coordinate variables.
- "all": Set variables referred to in ``'grid_mapping'``, ``'bounds'`` and
other attributes as coordinate variables.
Only existing variables can be set as coordinates. Missing variables
will be silently ignored.
drop_variables: str or iterable of str, optional
A variable or list of variables to exclude from being parsed from the
dataset. This may be useful to drop variables with problems or
Expand Down Expand Up @@ -691,6 +694,9 @@ def open_dataarray(
as coordinate variables.
- "all": Set variables referred to in ``'grid_mapping'``, ``'bounds'`` and
other attributes as coordinate variables.
Only existing variables can be set as coordinates. Missing variables
will be silently ignored.
drop_variables: str or iterable of str, optional
A variable or list of variables to exclude from being parsed from the
dataset. This may be useful to drop variables with problems or
Expand Down Expand Up @@ -1522,6 +1528,7 @@ def to_zarr(
synchronizer=None,
group: str | None = None,
encoding: Mapping | None = None,
*,
compute: Literal[True] = True,
consolidated: bool | None = None,
append_dim: Hashable | None = None,
Expand Down Expand Up @@ -1567,6 +1574,7 @@ def to_zarr(
synchronizer=None,
group: str | None = None,
encoding: Mapping | None = None,
*,
compute: bool = True,
consolidated: bool | None = None,
append_dim: Hashable | None = None,
Expand Down
2 changes: 2 additions & 0 deletions xarray/coding/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ def decode(self, variable: Variable, name: T_Name = None):
)

# special case DateTime to properly handle NaT
dtype: np.typing.DTypeLike
decoded_fill_value: Any
if _is_time_like(attrs.get("units")) and data.dtype.kind in "iu":
dtype, decoded_fill_value = np.int64, np.iinfo(np.int64).min
else:
Expand Down
Loading

0 comments on commit dc89546

Please sign in to comment.