From e6384be0e6cda8fc5fab583a5c27a9b024f6ae44 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Wed, 26 Jun 2024 14:52:34 +0200 Subject: [PATCH 1/8] =?UTF-8?q?`NaN`=20=E2=86=92=20`nan`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/getting-started-guide/faq.rst | 4 ++-- doc/user-guide/computation.rst | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/getting-started-guide/faq.rst b/doc/getting-started-guide/faq.rst index 7f99fa77e3a..58d5448cdf5 100644 --- a/doc/getting-started-guide/faq.rst +++ b/doc/getting-started-guide/faq.rst @@ -352,9 +352,9 @@ Some packages may have additional functionality beyond what is shown here. You c How does xarray handle missing values? -------------------------------------- -**xarray can handle missing values using ``np.NaN``** +**xarray can handle missing values using ``np.nan``** -- ``np.NaN`` is used to represent missing values in labeled arrays and datasets. It is a commonly used standard for representing missing or undefined numerical data in scientific computing. ``np.NaN`` is a constant value in NumPy that represents "Not a Number" or missing values. +- ``np.nan`` is used to represent missing values in labeled arrays and datasets. It is a commonly used standard for representing missing or undefined numerical data in scientific computing. ``np.nan`` is a constant value in NumPy that represents "Not a Number" or missing values. - Most of xarray's computation methods are designed to automatically handle missing values appropriately. diff --git a/doc/user-guide/computation.rst b/doc/user-guide/computation.rst index f99d41be538..23ecbedf61e 100644 --- a/doc/user-guide/computation.rst +++ b/doc/user-guide/computation.rst @@ -426,7 +426,7 @@ However, the functions also take missing values in the data into account: .. ipython:: python - data = xr.DataArray([np.NaN, 2, 4]) + data = xr.DataArray([np.nan, 2, 4]) weights = xr.DataArray([8, 1, 1]) data.weighted(weights).mean() @@ -444,7 +444,7 @@ If the weights add up to to 0, ``sum`` returns 0: data.weighted(weights).sum() -and ``mean``, ``std`` and ``var`` return ``NaN``: +and ``mean``, ``std`` and ``var`` return ``nan``: .. ipython:: python From 932db4ee985ea1eb6e6e476c5d0807490bacfed6 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Wed, 26 Jun 2024 15:06:22 +0200 Subject: [PATCH 2/8] new numpy scalar repr --- xarray/core/computation.py | 2 +- xarray/plot/facetgrid.py | 4 ++-- xarray/plot/utils.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/xarray/core/computation.py b/xarray/core/computation.py index f418d3821c2..7062d554616 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1064,7 +1064,7 @@ def apply_ufunc( supported: >>> magnitude(3, 4) - 5.0 + np.float64(5.0) >>> magnitude(3, np.array([0, 4])) array([3., 5.]) >>> magnitude(array, 0) diff --git a/xarray/plot/facetgrid.py b/xarray/plot/facetgrid.py index faf809a8a74..613362ed5d5 100644 --- a/xarray/plot/facetgrid.py +++ b/xarray/plot/facetgrid.py @@ -774,7 +774,7 @@ def _get_largest_lims(self) -> dict[str, tuple[float, float]]: >>> ds = xr.tutorial.scatter_example_dataset(seed=42) >>> fg = ds.plot.scatter(x="A", y="B", hue="y", row="x", col="w") >>> round(fg._get_largest_lims()["x"][0], 3) - -0.334 + np.float64(-0.334) """ lims_largest: dict[str, tuple[float, float]] = dict( x=(np.inf, -np.inf), y=(np.inf, -np.inf), z=(np.inf, -np.inf) @@ -817,7 +817,7 @@ def _set_lims( >>> fg = ds.plot.scatter(x="A", y="B", hue="y", row="x", col="w") >>> fg._set_lims(x=(-0.3, 0.3), y=(0, 2), z=(0, 4)) >>> fg.axs[0, 0].get_xlim(), fg.axs[0, 0].get_ylim() - ((-0.3, 0.3), (0.0, 2.0)) + ((np.float64(-0.3), np.float64(0.3)), (np.float64(0.0), np.float64(2.0))) """ lims_largest = self._get_largest_lims() diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 8789bc2f9c2..a0abe0c8cfd 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -811,11 +811,11 @@ def _update_axes( def _is_monotonic(coord, axis=0): """ >>> _is_monotonic(np.array([0, 1, 2])) - True + np.True_ >>> _is_monotonic(np.array([2, 1, 0])) - True + np.True_ >>> _is_monotonic(np.array([0, 2, 1])) - False + np.False_ """ if coord.shape[axis] < 3: return True From 4ae1ccb3e41411256a9fea4f5c7bf7572e089324 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Thu, 27 Jun 2024 12:26:23 +0200 Subject: [PATCH 3/8] unpin `numpy` in the docs [skip-ci] --- ci/requirements/doc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/requirements/doc.yml b/ci/requirements/doc.yml index 116eee7f702..39c2d4d6e88 100644 --- a/ci/requirements/doc.yml +++ b/ci/requirements/doc.yml @@ -21,7 +21,7 @@ dependencies: - nbsphinx - netcdf4>=1.5 - numba - - numpy>=1.21,<2 + - numpy>=1.21 - packaging>=21.3 - pandas>=1.4,!=2.1.0 - pooch From 28faa70b21fa6be69e2a141aacd8177b2d0c27c1 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Thu, 27 Jun 2024 14:06:01 +0200 Subject: [PATCH 4/8] try extracting the scalars to pass to `linspace` --- doc/user-guide/interpolation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/user-guide/interpolation.rst b/doc/user-guide/interpolation.rst index 311e1bf0129..53d8a52b342 100644 --- a/doc/user-guide/interpolation.rst +++ b/doc/user-guide/interpolation.rst @@ -292,8 +292,8 @@ Let's see how :py:meth:`~xarray.DataArray.interp` works on real data. axes[0].set_title("Raw data") # Interpolated data - new_lon = np.linspace(ds.lon[0], ds.lon[-1], ds.sizes["lon"] * 4) - new_lat = np.linspace(ds.lat[0], ds.lat[-1], ds.sizes["lat"] * 4) + new_lon = np.linspace(ds.lon[0].item(), ds.lon[-1].item(), ds.sizes["lon"] * 4) + new_lat = np.linspace(ds.lat[0].item(), ds.lat[-1].item(), ds.sizes["lat"] * 4) dsi = ds.interp(lat=new_lat, lon=new_lon) dsi.air.plot(ax=axes[1]) @savefig interpolation_sample3.png width=8in From f051d512b6a7db21af7561d8a431d04f510ba736 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Thu, 27 Jun 2024 22:03:47 +0200 Subject: [PATCH 5/8] use `numpy` instead of `numpy.array_api` [skip-ci] and mention that we're falling back to `numpy.array_api` in `numpy<2.0` --- doc/user-guide/testing.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/user-guide/testing.rst b/doc/user-guide/testing.rst index 13279eccb0b..d82d9d7d7d9 100644 --- a/doc/user-guide/testing.rst +++ b/doc/user-guide/testing.rst @@ -239,9 +239,10 @@ If the array type you want to generate has an array API-compliant top-level name you can use this neat trick: .. ipython:: python - :okwarning: - from numpy import array_api as xp # available in numpy 1.26.0 + import numpy as xp # compatible in numpy 2.0 + + # use `import numpy.array_api as xp` in numpy>=1.23,<2.0 from hypothesis.extra.array_api import make_strategies_namespace From 8357de5128da9c49d52c5286130182ef270e52ea Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Tue, 2 Jul 2024 06:52:50 -0600 Subject: [PATCH 6/8] Update ci/requirements/doc.yml --- ci/requirements/doc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/requirements/doc.yml b/ci/requirements/doc.yml index 39c2d4d6e88..cbbbaa16d7a 100644 --- a/ci/requirements/doc.yml +++ b/ci/requirements/doc.yml @@ -21,7 +21,7 @@ dependencies: - nbsphinx - netcdf4>=1.5 - numba - - numpy>=1.21 + - numpy>=2 - packaging>=21.3 - pandas>=1.4,!=2.1.0 - pooch From 0db06ac82c5d811a0611cd75d4043b8929b85ffa Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Thu, 11 Jul 2024 14:36:19 +0530 Subject: [PATCH 7/8] Remove 2D cross product doctests --- xarray/core/computation.py | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/xarray/core/computation.py b/xarray/core/computation.py index 7062d554616..77bd4444075 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1587,15 +1587,6 @@ def cross( array([-3, 6, -3]) Dimensions without coordinates: dim_0 - Vector cross-product with 2 dimensions, returns in the perpendicular - direction: - - >>> a = xr.DataArray([1, 2]) - >>> b = xr.DataArray([4, 5]) - >>> xr.cross(a, b, dim="dim_0") - Size: 8B - array(-3) - Vector cross-product with 3 dimensions but zeros at the last axis yields the same results as with 2 dimensions: @@ -1606,30 +1597,12 @@ def cross( array([ 0, 0, -3]) Dimensions without coordinates: dim_0 - One vector with dimension 2: - - >>> a = xr.DataArray( - ... [1, 2], - ... dims=["cartesian"], - ... coords=dict(cartesian=(["cartesian"], ["x", "y"])), - ... ) - >>> b = xr.DataArray( - ... [4, 5, 6], - ... dims=["cartesian"], - ... coords=dict(cartesian=(["cartesian"], ["x", "y", "z"])), - ... ) - >>> xr.cross(a, b, dim="cartesian") - Size: 24B - array([12, -6, -3]) - Coordinates: - * cartesian (cartesian) >> a = xr.DataArray( - ... [1, 2], + ... [1, 2, 0], ... dims=["cartesian"], - ... coords=dict(cartesian=(["cartesian"], ["x", "z"])), + ... coords=dict(cartesian=(["cartesian"], ["x", "z", "y"])), ... ) >>> b = xr.DataArray( ... [4, 5, 6], From 79024596efc56c312cd1eced6794110b98b7f6b2 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Thu, 11 Jul 2024 14:55:15 +0530 Subject: [PATCH 8/8] One more fix --- xarray/core/computation.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/xarray/core/computation.py b/xarray/core/computation.py index 77bd4444075..5d21d0836b9 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1597,24 +1597,6 @@ def cross( array([ 0, 0, -3]) Dimensions without coordinates: dim_0 - One vector with different dimension order: - - >>> a = xr.DataArray( - ... [1, 2, 0], - ... dims=["cartesian"], - ... coords=dict(cartesian=(["cartesian"], ["x", "z", "y"])), - ... ) - >>> b = xr.DataArray( - ... [4, 5, 6], - ... dims=["cartesian"], - ... coords=dict(cartesian=(["cartesian"], ["x", "y", "z"])), - ... ) - >>> xr.cross(a, b, dim="cartesian") - Size: 24B - array([-10, 2, 5]) - Coordinates: - * cartesian (cartesian)