Skip to content

Commit

Permalink
Merge branch 'main' into h5netcdf-new-features
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuehlbauer authored Sep 24, 2024
2 parents 74d3958 + 52f13d4 commit bbba5cf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pypi-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
path: dist
- name: Publish package to TestPyPI
if: github.event_name == 'push'
uses: pypa/[email protected].1
uses: pypa/[email protected].2
with:
repository_url: https://test.pypi.org/legacy/
verbose: true
Expand All @@ -111,6 +111,6 @@ jobs:
name: releases
path: dist
- name: Publish package to PyPI
uses: pypa/[email protected].1
uses: pypa/[email protected].2
with:
verbose: true
6 changes: 3 additions & 3 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10627,7 +10627,7 @@ def rolling(
--------
Dataset.cumulative
DataArray.rolling
core.rolling.DatasetRolling
DataArray.rolling_exp
"""
from xarray.core.rolling import DatasetRolling

Expand Down Expand Up @@ -10657,9 +10657,9 @@ def cumulative(
See Also
--------
Dataset.rolling
DataArray.cumulative
core.rolling.DatasetRolling
Dataset.rolling
Dataset.rolling_exp
"""
from xarray.core.rolling import DatasetRolling

Expand Down
6 changes: 4 additions & 2 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,14 @@ def convert_non_numpy_type(data):
else:
data = np.asarray(data)

if not isinstance(data, np.ndarray) and (
# immediately return array-like types except `numpy.ndarray` subclasses and `numpy` scalars
if not isinstance(data, np.ndarray | np.generic) and (
hasattr(data, "__array_function__") or hasattr(data, "__array_namespace__")
):
return cast("T_DuckArray", data)

# validate whether the data is valid data types.
# validate whether the data is valid data types. Also, explicitly cast `numpy`
# subclasses and `numpy` scalars to `numpy.ndarray`
data = np.asarray(data)

if data.dtype.kind in "OMm":
Expand Down
7 changes: 6 additions & 1 deletion xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2585,7 +2585,12 @@ def test_unchanged_types(self):
assert source_ndarray(x) is source_ndarray(as_compatible_data(x))

def test_converted_types(self):
for input_array in [[[0, 1, 2]], pd.DataFrame([[0, 1, 2]])]:
for input_array in [
[[0, 1, 2]],
pd.DataFrame([[0, 1, 2]]),
np.float64(1.4),
np.str_("abc"),
]:
actual = as_compatible_data(input_array)
assert_array_equal(np.asarray(input_array), actual)
assert np.ndarray is type(actual)
Expand Down

0 comments on commit bbba5cf

Please sign in to comment.