From 79b54afdfb1ef13c7478d196b60da15713865122 Mon Sep 17 00:00:00 2001 From: eschalk Date: Sun, 4 Feb 2024 17:30:32 +0100 Subject: [PATCH 01/18] Add nbytes to repr --- xarray/core/formatting.py | 66 +++++++++++++++++++++++++++++++-- xarray/core/options.py | 2 + xarray/tests/test_formatting.py | 58 ++++++++++++++++++++++++++++- 3 files changed, 120 insertions(+), 6 deletions(-) diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 92bfe2fbfc4..291e2ad8f59 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -1,5 +1,6 @@ """String formatting routines for __repr__. """ + from __future__ import annotations import contextlib @@ -25,6 +26,8 @@ if TYPE_CHECKING: from xarray.core.coordinates import AbstractCoordinates +UNITS = ("B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") + def pretty_print(x, numchars: int): """Given an object `x`, call `str(x)` and format the returned string so @@ -333,7 +336,12 @@ def summarize_variable( dims_str = "({}) ".format(", ".join(map(str, variable.dims))) else: dims_str = "" - front_str = f"{first_col}{dims_str}{variable.dtype} " + + if OPTIONS["display_nbytes"]: + nbytes_str = f" {render_human_readable_nbytes(variable.nbytes, attempt_constant_width=True)}" + else: + nbytes_str = "" + front_str = f"{first_col}{dims_str}{variable.dtype}{nbytes_str} " values_width = max_width - len(front_str) values_str = inline_variable_array_repr(variable, values_width) @@ -668,11 +676,14 @@ def array_repr(arr): start = f"", + f"{start}({dims}){nbytes_str}>", data_repr, ] - if hasattr(arr, "coords"): if arr.coords: col_width = _calculate_col_width(arr.coords) @@ -705,7 +716,11 @@ def array_repr(arr): @recursive_repr("") def dataset_repr(ds): - summary = [f""] + if OPTIONS["display_nbytes"]: + nbytes_str = f" {render_human_readable_nbytes(ds.nbytes)}" + else: + nbytes_str = "" + summary = [f""] col_width = _calculate_col_width(ds.variables) max_rows = OPTIONS["display_max_rows"] @@ -950,3 +965,46 @@ def shorten_list_repr(items: Sequence, max_items: int) -> str: 1:-1 ] # Convert to string and remove brackets return f"[{first_half}, ..., {second_half}]" + + +def render_human_readable_nbytes( + nbytes: int, + /, + *, + attempt_constant_width: bool = False, +) -> str: + """Renders simple human-readable byte count representation + + This is only a quick representation that should not be relied upon for precise needs. + + To get the exact byte count, please use the ``nbytes`` attribute directly. + + Parameters + ---------- + nbytes + Byte count + attempt_constant_width + For reasonable nbytes sizes, tries to render a fixed-width representation. + + Returns + ------- + Human-readable representation of the byte count + """ + dividend = float(nbytes) + divisor = 1000.0 + last_unit_available = UNITS[-1] + + for unit in UNITS: + if dividend < divisor or unit == last_unit_available: + break + dividend /= divisor + + dividend_str = f"{dividend:.0f}" + unit_str = f"{unit}" + + if attempt_constant_width: + dividend_str = dividend_str.rjust(3) + unit_str = unit_str.ljust(2) + + string = f"{dividend_str}{unit_str}" + return string diff --git a/xarray/core/options.py b/xarray/core/options.py index d116c350991..d5095cf734a 100644 --- a/xarray/core/options.py +++ b/xarray/core/options.py @@ -46,6 +46,7 @@ class T_Options(TypedDict): display_expand_data: Literal["default", True, False] display_expand_indexes: Literal["default", True, False] display_default_indexes: Literal["default", True, False] + display_nbytes: Literal["default", True, False] enable_cftimeindex: bool file_cache_maxsize: int keep_attrs: Literal["default", True, False] @@ -70,6 +71,7 @@ class T_Options(TypedDict): "display_expand_data": "default", "display_expand_indexes": "default", "display_default_indexes": False, + "display_nbytes": True, "enable_cftimeindex": True, "file_cache_maxsize": 128, "keep_attrs": "default", diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index 6ed4103aef7..ed14202b374 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -627,8 +627,9 @@ def test_repr_file_collapsed(tmp_path) -> None: arr_to_store = xr.DataArray(np.arange(300, dtype=np.int64), dims="test") arr_to_store.to_netcdf(tmp_path / "test.nc", engine="netcdf4") - with xr.open_dataarray(tmp_path / "test.nc") as arr, xr.set_options( - display_expand_data=False + with ( + xr.open_dataarray(tmp_path / "test.nc") as arr, + xr.set_options(display_expand_data=False), ): actual = repr(arr) expected = dedent( @@ -818,3 +819,56 @@ def test_empty_cftimeindex_repr() -> None: actual = repr(da.indexes) assert actual == expected + + +def test_display_nbytes() -> None: + xds = xr.Dataset( + { + "foo": np.arange(1200), + "bar": np.arange(111), + } + ) + + with xr.set_options(display_nbytes=False): + actual = repr(xds) + expected = """ + +Dimensions: (foo: 1200, bar: 111) +Coordinates: + * foo (foo) int64 0 1 2 3 4 5 6 7 ... 1193 1194 1195 1196 1197 1198 1199 + * bar (bar) int64 0 1 2 3 4 5 6 7 8 ... 103 104 105 106 107 108 109 110 +Data variables: + *empty* + """.strip() + assert actual == expected + + actual = repr(xds["foo"]) + expected = """ + +array([ 0, 1, 2, ..., 1197, 1198, 1199]) +Coordinates: + * foo (foo) int64 0 1 2 3 4 5 6 7 ... 1193 1194 1195 1196 1197 1198 1199 +""".strip() + assert actual == expected + + with xr.set_options(display_nbytes=True): + actual = repr(xds) + expected = """ + +Dimensions: (foo: 1200, bar: 111) +Coordinates: + * foo (foo) int64 10kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 + * bar (bar) int64 888B 0 1 2 3 4 5 6 7 ... 104 105 106 107 108 109 110 +Data variables: + *empty* + """.strip() + assert actual == expected + + actual = repr(xds["foo"]) + expected = """ + +array([ 0, 1, 2, ..., 1197, 1198, 1199]) +Coordinates: + * foo (foo) int64 10kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 +""".strip() + assert actual == expected From 927956368cf26a091c39af73bdde6be64de4c609 Mon Sep 17 00:00:00 2001 From: eschalk Date: Sun, 4 Feb 2024 17:31:51 +0100 Subject: [PATCH 02/18] Disable by default --- xarray/core/options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/options.py b/xarray/core/options.py index d5095cf734a..944170e0a17 100644 --- a/xarray/core/options.py +++ b/xarray/core/options.py @@ -71,7 +71,7 @@ class T_Options(TypedDict): "display_expand_data": "default", "display_expand_indexes": "default", "display_default_indexes": False, - "display_nbytes": True, + "display_nbytes": False, "enable_cftimeindex": True, "file_cache_maxsize": 128, "keep_attrs": "default", From 8611840760958962518a5a61fbfe39989e57ebda Mon Sep 17 00:00:00 2001 From: eschalk Date: Sun, 4 Feb 2024 17:38:14 +0100 Subject: [PATCH 03/18] What's new --- doc/whats-new.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 1b0f2f18efb..94c7e6020dc 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -23,6 +23,10 @@ v2024.02.0 (unreleased) New Features ~~~~~~~~~~~~ +- Added a simple `nbytes` representation in DataArrays and Dataset `repr` (opt-in). + To enable, use `xr.set_options(display_nbytes=True)` + (:issue:`8690`, :pull:`8702`). + By `Etienne Schalk `_. - Allow negative frequency strings (e.g. ``"-1YE"``). These strings are for example used in :py:func:`date_range`, and :py:func:`cftime_range` (:pull:`8651`). By `Mathias Hauser `_. From 560a35dc9eabc27144a2e397ad5f847f7cd4567c Mon Sep 17 00:00:00 2001 From: eschalk Date: Sun, 4 Feb 2024 20:22:12 +0100 Subject: [PATCH 04/18] Specify dtype explictly as Windows seems to default on int32 --- xarray/tests/test_formatting.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index ed14202b374..9b6aaf7d632 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -824,8 +824,8 @@ def test_empty_cftimeindex_repr() -> None: def test_display_nbytes() -> None: xds = xr.Dataset( { - "foo": np.arange(1200), - "bar": np.arange(111), + "foo": np.arange(1200, dtype=np.int64), + "bar": np.arange(111, dtype=np.int64), } ) From aafacd4ebcd4b553c2e5e05e78e0d499ad386f04 Mon Sep 17 00:00:00 2001 From: eschalk Date: Sun, 4 Feb 2024 20:56:24 +0100 Subject: [PATCH 05/18] Use int16 --- xarray/tests/test_formatting.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index 9b6aaf7d632..708d249a9b8 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -824,19 +824,22 @@ def test_empty_cftimeindex_repr() -> None: def test_display_nbytes() -> None: xds = xr.Dataset( { - "foo": np.arange(1200, dtype=np.int64), - "bar": np.arange(111, dtype=np.int64), + "foo": np.arange(1200, dtype=np.int16), + "bar": np.arange(111, dtype=np.int16), } ) + # Note: int16 is used to ensure that dtype is shown in the + # numpy array representation for all OSes included Windows + with xr.set_options(display_nbytes=False): actual = repr(xds) expected = """ Dimensions: (foo: 1200, bar: 111) Coordinates: - * foo (foo) int64 0 1 2 3 4 5 6 7 ... 1193 1194 1195 1196 1197 1198 1199 - * bar (bar) int64 0 1 2 3 4 5 6 7 8 ... 103 104 105 106 107 108 109 110 + * foo (foo) int16 0 1 2 3 4 5 6 7 ... 1193 1194 1195 1196 1197 1198 1199 + * bar (bar) int16 0 1 2 3 4 5 6 7 8 ... 103 104 105 106 107 108 109 110 Data variables: *empty* """.strip() @@ -845,20 +848,20 @@ def test_display_nbytes() -> None: actual = repr(xds["foo"]) expected = """ -array([ 0, 1, 2, ..., 1197, 1198, 1199]) +array([ 0, 1, 2, ..., 1197, 1198, 1199], dtype=int16) Coordinates: - * foo (foo) int64 0 1 2 3 4 5 6 7 ... 1193 1194 1195 1196 1197 1198 1199 + * foo (foo) int16 0 1 2 3 4 5 6 7 ... 1193 1194 1195 1196 1197 1198 1199 """.strip() assert actual == expected with xr.set_options(display_nbytes=True): actual = repr(xds) expected = """ - + Dimensions: (foo: 1200, bar: 111) Coordinates: - * foo (foo) int64 10kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 - * bar (bar) int64 888B 0 1 2 3 4 5 6 7 ... 104 105 106 107 108 109 110 + * foo (foo) int16 2kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 + * bar (bar) int16 222B 0 1 2 3 4 5 6 7 ... 104 105 106 107 108 109 110 Data variables: *empty* """.strip() @@ -866,9 +869,9 @@ def test_display_nbytes() -> None: actual = repr(xds["foo"]) expected = """ - -array([ 0, 1, 2, ..., 1197, 1198, 1199]) + +array([ 0, 1, 2, ..., 1197, 1198, 1199], dtype=int16) Coordinates: - * foo (foo) int64 10kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 + * foo (foo) int16 2kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 """.strip() assert actual == expected From 12bd33dfb080d964ad997a6cdb363e7e1e293dbc Mon Sep 17 00:00:00 2001 From: eschalk Date: Sun, 4 Feb 2024 22:33:00 +0100 Subject: [PATCH 06/18] PR comments: Removed global option + size format in repr header --- doc/whats-new.rst | 3 +- xarray/core/formatting.py | 21 ++++------- xarray/core/options.py | 2 - xarray/tests/test_formatting.py | 67 +++++++++++---------------------- 4 files changed, 30 insertions(+), 63 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 94c7e6020dc..b72b1232784 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -23,8 +23,7 @@ v2024.02.0 (unreleased) New Features ~~~~~~~~~~~~ -- Added a simple `nbytes` representation in DataArrays and Dataset `repr` (opt-in). - To enable, use `xr.set_options(display_nbytes=True)` +- Added a simple `nbytes` representation in DataArrays and Dataset `repr`. (:issue:`8690`, :pull:`8702`). By `Etienne Schalk `_. - Allow negative frequency strings (e.g. ``"-1YE"``). These strings are for example used diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 291e2ad8f59..5c4aed6e39e 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -337,10 +337,9 @@ def summarize_variable( else: dims_str = "" - if OPTIONS["display_nbytes"]: - nbytes_str = f" {render_human_readable_nbytes(variable.nbytes, attempt_constant_width=True)}" - else: - nbytes_str = "" + nbytes_str = ( + f" {render_human_readable_nbytes(variable.nbytes, attempt_constant_width=True)}" + ) front_str = f"{first_col}{dims_str}{variable.dtype}{nbytes_str} " values_width = max_width - len(front_str) @@ -676,12 +675,9 @@ def array_repr(arr): start = f"", + f"{start}({dims})> Size: {nbytes_str}", data_repr, ] if hasattr(arr, "coords"): @@ -716,11 +712,8 @@ def array_repr(arr): @recursive_repr("") def dataset_repr(ds): - if OPTIONS["display_nbytes"]: - nbytes_str = f" {render_human_readable_nbytes(ds.nbytes)}" - else: - nbytes_str = "" - summary = [f""] + nbytes_str = render_human_readable_nbytes(ds.nbytes) + summary = [f" Size: {nbytes_str}"] col_width = _calculate_col_width(ds.variables) max_rows = OPTIONS["display_max_rows"] diff --git a/xarray/core/options.py b/xarray/core/options.py index 944170e0a17..d116c350991 100644 --- a/xarray/core/options.py +++ b/xarray/core/options.py @@ -46,7 +46,6 @@ class T_Options(TypedDict): display_expand_data: Literal["default", True, False] display_expand_indexes: Literal["default", True, False] display_default_indexes: Literal["default", True, False] - display_nbytes: Literal["default", True, False] enable_cftimeindex: bool file_cache_maxsize: int keep_attrs: Literal["default", True, False] @@ -71,7 +70,6 @@ class T_Options(TypedDict): "display_expand_data": "default", "display_expand_indexes": "default", "display_default_indexes": False, - "display_nbytes": False, "enable_cftimeindex": True, "file_cache_maxsize": 128, "keep_attrs": "default", diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index 708d249a9b8..f7770f4477a 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -316,12 +316,12 @@ def test_diff_array_repr(self) -> None: R array([1, 2], dtype=int64) Differing coordinates: - L * x (x) %cU1 'a' 'b' - R * x (x) %cU1 'a' 'c' + L * x (x) %cU1 8B 'a' 'b' + R * x (x) %cU1 8B 'a' 'c' Coordinates only on the left object: - * y (y) int64 1 2 3 + * y (y) int64 24B 1 2 3 Coordinates only on the right object: - label (x) int64 1 2 + label (x) int64 16B 1 2 Differing attributes: L units: m R units: kg @@ -436,22 +436,22 @@ def test_diff_dataset_repr(self) -> None: Differing dimensions: (x: 2, y: 3) != (x: 2) Differing coordinates: - L * x (x) %cU1 'a' 'b' + L * x (x) %cU1 8B 'a' 'b' Differing variable attributes: foo: bar - R * x (x) %cU1 'a' 'c' + R * x (x) %cU1 8B 'a' 'c' Differing variable attributes: source: 0 foo: baz Coordinates only on the left object: - * y (y) int64 1 2 3 + * y (y) int64 24B 1 2 3 Coordinates only on the right object: - label (x) int64 1 2 + label (x) int64 16B 1 2 Differing data variables: - L var1 (x, y) int64 1 2 3 4 5 6 - R var1 (x) int64 1 2 + L var1 (x, y) int64 48B 1 2 3 4 5 6 + R var1 (x) int64 16B 1 2 Data variables only on the left object: - var2 (x) int64 3 4 + var2 (x) int64 16B 3 4 Differing attributes: L title: mytitle R title: newtitle @@ -472,7 +472,7 @@ def test_array_repr(self) -> None: actual = formatting.array_repr(ds_12) expected = dedent( """\ - + Size: 8B array([0]) Dimensions without coordinates: test""" ) @@ -491,7 +491,7 @@ def test_array_repr(self) -> None: actual = formatting.array_repr(ds[(1, 2)]) expected = dedent( """\ - + Size: 8B 0 Dimensions without coordinates: test""" ) @@ -832,46 +832,23 @@ def test_display_nbytes() -> None: # Note: int16 is used to ensure that dtype is shown in the # numpy array representation for all OSes included Windows - with xr.set_options(display_nbytes=False): - actual = repr(xds) - expected = """ - -Dimensions: (foo: 1200, bar: 111) -Coordinates: - * foo (foo) int16 0 1 2 3 4 5 6 7 ... 1193 1194 1195 1196 1197 1198 1199 - * bar (bar) int16 0 1 2 3 4 5 6 7 8 ... 103 104 105 106 107 108 109 110 -Data variables: - *empty* - """.strip() - assert actual == expected - - actual = repr(xds["foo"]) - expected = """ - -array([ 0, 1, 2, ..., 1197, 1198, 1199], dtype=int16) -Coordinates: - * foo (foo) int16 0 1 2 3 4 5 6 7 ... 1193 1194 1195 1196 1197 1198 1199 -""".strip() - assert actual == expected - - with xr.set_options(display_nbytes=True): - actual = repr(xds) - expected = """ - + actual = repr(xds) + expected = """ + Size: 3kB Dimensions: (foo: 1200, bar: 111) Coordinates: * foo (foo) int16 2kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 * bar (bar) int16 222B 0 1 2 3 4 5 6 7 ... 104 105 106 107 108 109 110 Data variables: *empty* - """.strip() - assert actual == expected + """.strip() + assert actual == expected - actual = repr(xds["foo"]) - expected = """ - + actual = repr(xds["foo"]) + expected = """ + Size: 2kB array([ 0, 1, 2, ..., 1197, 1198, 1199], dtype=int16) Coordinates: * foo (foo) int16 2kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 """.strip() - assert actual == expected + assert actual == expected From be042cfaaf6145da8887a2bda5af53801062b2ea Mon Sep 17 00:00:00 2001 From: eschalk Date: Mon, 5 Feb 2024 21:19:48 +0100 Subject: [PATCH 07/18] Remove width justified --- xarray/core/formatting.py | 4 +--- xarray/tests/test_formatting.py | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 5c4aed6e39e..2ec5513a554 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -337,9 +337,7 @@ def summarize_variable( else: dims_str = "" - nbytes_str = ( - f" {render_human_readable_nbytes(variable.nbytes, attempt_constant_width=True)}" - ) + nbytes_str = f" {render_human_readable_nbytes(variable.nbytes)}" front_str = f"{first_col}{dims_str}{variable.dtype}{nbytes_str} " values_width = max_width - len(front_str) diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index f7770f4477a..413ff8e39d4 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -837,8 +837,8 @@ def test_display_nbytes() -> None: Size: 3kB Dimensions: (foo: 1200, bar: 111) Coordinates: - * foo (foo) int16 2kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 - * bar (bar) int16 222B 0 1 2 3 4 5 6 7 ... 104 105 106 107 108 109 110 + * foo (foo) int16 2kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 + * bar (bar) int16 222B 0 1 2 3 4 5 6 7 ... 104 105 106 107 108 109 110 Data variables: *empty* """.strip() @@ -849,6 +849,6 @@ def test_display_nbytes() -> None: Size: 2kB array([ 0, 1, 2, ..., 1197, 1198, 1199], dtype=int16) Coordinates: - * foo (foo) int16 2kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 + * foo (foo) int16 2kB 0 1 2 3 4 5 6 ... 1194 1195 1196 1197 1198 1199 """.strip() assert actual == expected From 85f6ee4f2d9d820d39ca9ab64619a098a791a7f4 Mon Sep 17 00:00:00 2001 From: eschalk Date: Mon, 5 Feb 2024 23:39:18 +0100 Subject: [PATCH 08/18] Remove problematic backslashes --- xarray/backends/api.py | 34 ++++++++++++++++++---------------- xarray/core/combine.py | 8 ++++---- xarray/core/computation.py | 13 ++++++++----- xarray/core/concat.py | 2 +- xarray/core/dataarray.py | 38 +++++++++++++++++++------------------- xarray/core/dataset.py | 26 +++++++++++++------------- xarray/core/merge.py | 8 ++++---- xarray/core/resample.py | 2 +- xarray/core/variable.py | 18 ++++++++---------- 9 files changed, 76 insertions(+), 73 deletions(-) diff --git a/xarray/backends/api.py b/xarray/backends/api.py index 670a0ec6d68..e4338021f43 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -419,8 +419,8 @@ def open_dataset( ends with .gz, in which case the file is gunzipped and opened with scipy.io.netcdf (only netCDF3 supported). Byte-strings or file-like objects are opened by scipy.io.netcdf (netCDF3) or h5py (netCDF4/HDF). - engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio", \ - "zarr", None}, installed backend \ + engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio",, + "zarr", None}, installed backend, or subclass of xarray.backends.BackendEntrypoint, optional Engine to use when reading files. If not provided, the default engine is chosen based on available dependencies, with a preference for @@ -626,8 +626,8 @@ def open_dataarray( ends with .gz, in which case the file is gunzipped and opened with scipy.io.netcdf (only netCDF3 supported). Byte-strings or file-like objects are opened by scipy.io.netcdf (netCDF3) or h5py (netCDF4/HDF). - engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio", \ - "zarr", None}, installed backend \ + engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio",, + "zarr", None}, installed backend, or subclass of xarray.backends.BackendEntrypoint, optional Engine to use when reading files. If not provided, the default engine is chosen based on available dependencies, with a preference for @@ -791,13 +791,15 @@ def open_dataarray( def open_mfdataset( paths: str | NestedSequence[str | os.PathLike], chunks: T_Chunks | None = None, - concat_dim: str - | DataArray - | Index - | Sequence[str] - | Sequence[DataArray] - | Sequence[Index] - | None = None, + concat_dim: ( + str + | DataArray + | Index + | Sequence[str] + | Sequence[DataArray] + | Sequence[Index] + | None + ) = None, compat: CompatOptions = "no_conflicts", preprocess: Callable[[Dataset], Dataset] | None = None, engine: T_Engine | None = None, @@ -847,7 +849,7 @@ def open_mfdataset( combine : {"by_coords", "nested"}, optional Whether ``xarray.combine_by_coords`` or ``xarray.combine_nested`` is used to combine all the data. Default is to use ``xarray.combine_by_coords``. - compat : {"identical", "equals", "broadcast_equals", \ + compat : {"identical", "equals", "broadcast_equals",, "no_conflicts", "override"}, default: "no_conflicts" String indicating how to compare variables of the same name for potential conflicts when merging: @@ -866,8 +868,8 @@ def open_mfdataset( If provided, call this function on each dataset prior to concatenation. You can find the file-name from which each dataset was loaded in ``ds.encoding["source"]``. - engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio", \ - "zarr", None}, installed backend \ + engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio",, + "zarr", None}, installed backend, or subclass of xarray.backends.BackendEntrypoint, optional Engine to use when reading files. If not provided, the default engine is chosen based on available dependencies, with a preference for @@ -917,7 +919,7 @@ def open_mfdataset( Path of the file used to read global attributes from. By default global attributes are read from the first file provided, with wildcard matches sorted by filename. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts",, "override"} or callable, default: "override" A callable or a string indicating how to combine attrs of the objects being merged: @@ -1390,7 +1392,7 @@ def save_mfdataset( mode : {"w", "a"}, optional Write ("w") or append ("a") mode. If mode="w", any existing file at these locations will be overwritten. - format : {"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT", \ + format : {"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT",, "NETCDF3_CLASSIC"}, optional **kwargs : additional arguments are passed along to ``to_netcdf`` diff --git a/xarray/core/combine.py b/xarray/core/combine.py index 10f194bf9f5..6e794bd898b 100644 --- a/xarray/core/combine.py +++ b/xarray/core/combine.py @@ -372,7 +372,7 @@ def _nested_combine( def combine_nested( datasets: DATASET_HYPERCUBE, - concat_dim: (str | DataArray | None | Sequence[str | DataArray | pd.Index | None]), + concat_dim: str | DataArray | None | Sequence[str | DataArray | pd.Index | None], compat: str = "no_conflicts", data_vars: str = "all", coords: str = "different", @@ -413,7 +413,7 @@ def combine_nested( nested-list input along which to merge. Must be the same length as the depth of the list passed to ``datasets``. - compat : {"identical", "equals", "broadcast_equals", \ + compat : {"identical", "equals", "broadcast_equals", "no_conflicts", "override"}, optional String indicating how to compare variables of the same name for potential merge conflicts: @@ -448,7 +448,7 @@ def combine_nested( - "override": if indexes are of same size, rewrite indexes to be those of the first object with that dimension. Indexes for the same dimension must have the same size in all objects. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", "override"} or callable, default: "drop" A callable or a string indicating how to combine attrs of the objects being merged: @@ -738,7 +738,7 @@ def combine_by_coords( those of the first object with that dimension. Indexes for the same dimension must have the same size in all objects. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", "override"} or callable, default: "no_conflicts" A callable or a string indicating how to combine attrs of the objects being merged: diff --git a/xarray/core/computation.py b/xarray/core/computation.py index dda72c0163b..3d88555e65a 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1,6 +1,7 @@ """ Functions for applying functions that act on arrays to xarray's labeled data. """ + from __future__ import annotations import functools @@ -223,7 +224,7 @@ def build_output_coords_and_indexes( exclude_dims : set, optional Dimensions excluded from the operation. Coordinates along these dimensions are dropped. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", "override"} or callable, default: "drop" A callable or a string indicating how to combine attrs of the objects being merged: @@ -731,9 +732,11 @@ def apply_variable_ufunc( output_dims = [broadcast_dims + out for out in signature.output_core_dims] input_data = [ - broadcast_compat_data(arg, broadcast_dims, core_dims) - if isinstance(arg, Variable) - else arg + ( + broadcast_compat_data(arg, broadcast_dims, core_dims) + if isinstance(arg, Variable) + else arg + ) for arg, core_dims in zip(args, signature.input_core_dims) ] @@ -931,7 +934,7 @@ def apply_ufunc( the style of NumPy universal functions [1]_ (if this is not the case, set ``vectorize=True``). If this function returns multiple outputs, you must set ``output_core_dims`` as well. - *args : Dataset, DataArray, DataArrayGroupBy, DatasetGroupBy, Variable, \ + *args : Dataset, DataArray, DataArrayGroupBy, DatasetGroupBy, Variable, numpy.ndarray, dask.array.Array or scalar Mix of labeled and/or unlabeled arrays to which to apply the function. input_core_dims : sequence of sequence, optional diff --git a/xarray/core/concat.py b/xarray/core/concat.py index 26cf36b3b07..200a46053f6 100644 --- a/xarray/core/concat.py +++ b/xarray/core/concat.py @@ -148,7 +148,7 @@ def concat( - "override": if indexes are of same size, rewrite indexes to be those of the first object with that dimension. Indexes for the same dimension must have the same size in all objects. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", "override"} or callable, default: "override" A callable or a string indicating how to combine attrs of the objects being merged: diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 099a94592fa..3483f39f64a 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -3437,7 +3437,7 @@ def interpolate_na( ---------- dim : Hashable or None, optional Specifies the dimension along which to interpolate. - method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial", \ + method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial", "barycentric", "krogh", "pchip", "spline", "akima"}, default: "linear" String indicating which method to use for interpolation: @@ -3995,7 +3995,7 @@ def to_netcdf( Write ('w') or append ('a') mode. If mode='w', any existing file at this location will be overwritten. If mode='a', existing variables will be overwritten. - format : {"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT", \ + format : {"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT", "NETCDF3_CLASSIC"}, optional File format for the resulting netCDF file: @@ -4983,10 +4983,12 @@ def dot( def sortby( self, - variables: Hashable - | DataArray - | Sequence[Hashable | DataArray] - | Callable[[Self], Hashable | DataArray | Sequence[Hashable | DataArray]], + variables: ( + Hashable + | DataArray + | Sequence[Hashable | DataArray] + | Callable[[Self], Hashable | DataArray | Sequence[Hashable | DataArray]] + ), ascending: bool = True, ) -> Self: """Sort object by labels or values (along an axis). @@ -5232,7 +5234,7 @@ def differentiate( edge_order: Literal[1, 2] = 1, datetime_unit: DatetimeUnitOptions = None, ) -> Self: - """ Differentiate the array with the second order accurate central + """Differentiate the array with the second order accurate central differences. .. note:: @@ -5245,7 +5247,7 @@ def differentiate( The coordinate to be used to compute the gradient. edge_order : {1, 2}, default: 1 N-th order accurate differences at the boundaries. - datetime_unit : {"W", "D", "h", "m", "s", "ms", \ + datetime_unit : {"W", "D", "h", "m", "s", "ms", "us", "ns", "ps", "fs", "as", None}, optional Unit to compute gradient. Only valid for datetime coordinate. "Y" and "M" are not available as datetime_unit. @@ -5304,7 +5306,7 @@ def integrate( ---------- coord : Hashable, or sequence of Hashable Coordinate(s) used for the integration. - datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', \ + datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', 'ps', 'fs', 'as', None}, optional Specify the unit if a datetime coordinate is used. @@ -5361,7 +5363,7 @@ def cumulative_integrate( ---------- coord : Hashable, or sequence of Hashable Coordinate(s) used for the integration. - datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', \ + datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', 'ps', 'fs', 'as', None}, optional Specify the unit if a datetime coordinate is used. @@ -5596,14 +5598,12 @@ def pad( self, pad_width: Mapping[Any, int | tuple[int, int]] | None = None, mode: PadModeOptions = "constant", - stat_length: int - | tuple[int, int] - | Mapping[Any, tuple[int, int]] - | None = None, - constant_values: float - | tuple[float, float] - | Mapping[Any, tuple[float, float]] - | None = None, + stat_length: ( + int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None + ) = None, + constant_values: ( + float | tuple[float, float] | Mapping[Any, tuple[float, float]] | None + ) = None, end_values: int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None = None, reflect_type: PadReflectOptions = None, keep_attrs: bool | None = None, @@ -5625,7 +5625,7 @@ def pad( Mapping with the form of {dim: (pad_before, pad_after)} describing the number of values padded along each dimension. {dim: pad} is a shortcut for pad_before = pad_after = pad - mode : {"constant", "edge", "linear_ramp", "maximum", "mean", "median", \ + mode : {"constant", "edge", "linear_ramp", "maximum", "mean", "median", "minimum", "reflect", "symmetric", "wrap"}, default: "constant" How to pad the DataArray (taken from numpy docs): diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 7fc689eef7b..c239648a6d2 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -2230,7 +2230,7 @@ def to_netcdf( Write ('w') or append ('a') mode. If mode='w', any existing file at this location will be overwritten. If mode='a', existing variables will be overwritten. - format : {"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT", \ + format : {"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT",, "NETCDF3_CLASSIC"}, optional File format for the resulting netCDF file: @@ -3801,7 +3801,7 @@ def interp( New coordinate can be a scalar, array-like or DataArray. If DataArrays are passed as new coordinates, their dimensions are used for the broadcasting. Missing values are skipped. - method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial", \ + method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial",, "barycentric", "krogh", "pchip", "spline", "akima"}, default: "linear" String indicating which method to use for interpolation: @@ -4080,7 +4080,7 @@ def interp_like( Object with an 'indexes' attribute giving a mapping from dimension names to an 1d array-like, which provides coordinates upon which to index the variables in this dataset. Missing values are skipped. - method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial", \ + method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial",, "barycentric", "krogh", "pchip", "spline", "akima"}, default: "linear" String indicating which method to use for interpolation: @@ -5646,7 +5646,7 @@ def merge( overwrite_vars : hashable or iterable of hashable, optional If provided, update variables of these name(s) without checking for conflicts in this dataset. - compat : {"identical", "equals", "broadcast_equals", \ + compat : {"identical", "equals", "broadcast_equals",, "no_conflicts", "override", "minimal"}, default: "no_conflicts" String indicating how to compare variables of the same name for potential conflicts: @@ -5662,7 +5662,7 @@ def merge( - 'override': skip comparing and pick variable from first dataset - 'minimal': drop conflicting coordinates - join : {"outer", "inner", "left", "right", "exact", "override"}, \ + join : {"outer", "inner", "left", "right", "exact", "override"},, default: "outer" Method for joining ``self`` and ``other`` along shared dimensions: @@ -5677,7 +5677,7 @@ def merge( fill_value : scalar or dict-like, optional Value to use for newly missing values. If a dict-like, maps variable names (including coordinates) to fill values. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts",, "override"} or callable, default: "override" A callable or a string indicating how to combine attrs of the objects being merged: @@ -6466,7 +6466,7 @@ def interpolate_na( ---------- dim : Hashable or None, optional Specifies the dimension along which to interpolate. - method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial", \ + method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial",, "barycentric", "krogh", "pchip", "spline", "akima"}, default: "linear" String indicating which method to use for interpolation: @@ -7487,7 +7487,7 @@ def from_dict(cls, d: Mapping[Any, Any]) -> Self: ---------- d : dict-like Mapping with a minimum structure of - ``{"var_0": {"dims": [..], "data": [..]}, \ + ``{"var_0": {"dims": [..], "data": [..]},, ...}`` Returns @@ -8265,7 +8265,7 @@ def differentiate( edge_order: Literal[1, 2] = 1, datetime_unit: DatetimeUnitOptions | None = None, ) -> Self: - """ Differentiate with the second order accurate central + """Differentiate with the second order accurate central differences. .. note:: @@ -8278,7 +8278,7 @@ def differentiate( The coordinate to be used to compute the gradient. edge_order : {1, 2}, default: 1 N-th order accurate differences at the boundaries. - datetime_unit : None or {"Y", "M", "W", "D", "h", "m", "s", "ms", \ + datetime_unit : None or {"Y", "M", "W", "D", "h", "m", "s", "ms",, "us", "ns", "ps", "fs", "as", None}, default: None Unit to compute gradient. Only valid for datetime coordinate. @@ -8346,7 +8346,7 @@ def integrate( ---------- coord : hashable, or sequence of hashable Coordinate(s) used for the integration. - datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', \ + datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns',, 'ps', 'fs', 'as', None}, optional Specify the unit if datetime coordinate is used. @@ -8469,7 +8469,7 @@ def cumulative_integrate( ---------- coord : hashable, or sequence of hashable Coordinate(s) used for the integration. - datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', \ + datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns',, 'ps', 'fs', 'as', None}, optional Specify the unit if datetime coordinate is used. @@ -8997,7 +8997,7 @@ def pad( Mapping with the form of {dim: (pad_before, pad_after)} describing the number of values padded along each dimension. {dim: pad} is a shortcut for pad_before = pad_after = pad - mode : {"constant", "edge", "linear_ramp", "maximum", "mean", "median", \ + mode : {"constant", "edge", "linear_ramp", "maximum", "mean", "median",, "minimum", "reflect", "symmetric", "wrap"}, default: "constant" How to pad the DataArray (taken from numpy docs): diff --git a/xarray/core/merge.py b/xarray/core/merge.py index a8e54ad1231..350e3895061 100644 --- a/xarray/core/merge.py +++ b/xarray/core/merge.py @@ -208,7 +208,7 @@ def merge_collected( prioritized : mapping compat : str Type of equality check to use when checking for conflicts. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts",, "override"} or callable, default: "override" A callable or a string indicating how to combine attrs of the objects being merged: @@ -666,7 +666,7 @@ def merge_core( Compatibility checks to use when merging variables. join : {"outer", "inner", "left", "right"}, optional How to combine objects with different indexes. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts",, "override"} or callable, default: "override" How to combine attributes of objects priority_arg : int, optional @@ -762,7 +762,7 @@ def merge( objects : iterable of Dataset or iterable of DataArray or iterable of dict-like Merge together all variables from these objects. If any of them are DataArray objects, they must have a name. - compat : {"identical", "equals", "broadcast_equals", "no_conflicts", \ + compat : {"identical", "equals", "broadcast_equals", "no_conflicts",, "override", "minimal"}, default: "no_conflicts" String indicating how to compare variables of the same name for potential conflicts: @@ -795,7 +795,7 @@ def merge( Value to use for newly missing values. If a dict-like, maps variable names to fill values. Use a data array's name to refer to its values. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts",, "override"} or callable, default: "override" A callable or a string indicating how to combine attrs of the objects being merged: diff --git a/xarray/core/resample.py b/xarray/core/resample.py index 3bb158acfdb..c88de3f3de9 100644 --- a/xarray/core/resample.py +++ b/xarray/core/resample.py @@ -145,7 +145,7 @@ def interpolate(self, kind: InterpOptions = "linear") -> T_Xarray: Parameters ---------- - kind : {"linear", "nearest", "zero", "slinear", \ + kind : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial"}, default: "linear" The method used to interpolate. The method should be supported by the scipy interpolator: diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 32323bb2e64..94324c1d57f 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -1231,14 +1231,12 @@ def pad( self, pad_width: Mapping[Any, int | tuple[int, int]] | None = None, mode: PadModeOptions = "constant", - stat_length: int - | tuple[int, int] - | Mapping[Any, tuple[int, int]] - | None = None, - constant_values: float - | tuple[float, float] - | Mapping[Any, tuple[float, float]] - | None = None, + stat_length: ( + int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None + ) = None, + constant_values: ( + float | tuple[float, float] | Mapping[Any, tuple[float, float]] | None + ) = None, end_values: int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None = None, reflect_type: PadReflectOptions = None, keep_attrs: bool | None = None, @@ -1794,7 +1792,7 @@ def concat( This option is used internally to speed-up groupby operations. If `shortcut` is True, some checks of internal consistency between arrays to concatenate are skipped. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", "override"}, default: "override" String indicating how to combine attrs of the objects being merged: @@ -2961,7 +2959,7 @@ def concat( This option is used internally to speed-up groupby operations. If `shortcut` is True, some checks of internal consistency between arrays to concatenate are skipped. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", "override"}, default: "override" String indicating how to combine attrs of the objects being merged: From 655f0af1e1de1f12cddedd7fa4f278a64ffe7aa7 Mon Sep 17 00:00:00 2001 From: eschalk Date: Mon, 5 Feb 2024 23:45:14 +0100 Subject: [PATCH 09/18] pytest-accept --- xarray/backends/api.py | 6 +- xarray/coding/cftimeindex.py | 12 +- xarray/core/_aggregations.py | 1256 ++++++++++++------------- xarray/core/accessor_dt.py | 34 +- xarray/core/accessor_str.py | 144 +-- xarray/core/alignment.py | 98 +- xarray/core/combine.py | 114 +-- xarray/core/common.py | 278 +++--- xarray/core/computation.py | 126 +-- xarray/core/concat.py | 32 +- xarray/core/coordinates.py | 28 +- xarray/core/dataarray.py | 866 +++++++++-------- xarray/core/dataset.py | 1046 ++++++++++---------- xarray/core/groupby.py | 32 +- xarray/core/merge.py | 130 +-- xarray/core/options.py | 5 +- xarray/core/parallel.py | 12 +- xarray/core/rolling.py | 14 +- xarray/core/rolling_exp.py | 12 +- xarray/core/variable.py | 12 +- xarray/datatree_/datatree/datatree.py | 12 +- xarray/namedarray/_aggregations.py | 80 +- xarray/namedarray/_array_api.py | 12 +- xarray/plot/utils.py | 10 +- 24 files changed, 2276 insertions(+), 2095 deletions(-) diff --git a/xarray/backends/api.py b/xarray/backends/api.py index e4338021f43..c1160850087 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -1438,12 +1438,12 @@ def save_mfdataset( ... coords={"time": pd.date_range("2010-01-01", freq="ME", periods=48)}, ... ) >>> ds - + Size: 768B Dimensions: (time: 48) Coordinates: - * time (time) datetime64[ns] 2010-01-31 2010-02-28 ... 2013-12-31 + * time (time) datetime64[ns] 384B 2010-01-31 2010-02-28 ... 2013-12-31 Data variables: - a (time) float64 0.0 0.02128 0.04255 0.06383 ... 0.9574 0.9787 1.0 + a (time) float64 384B 0.0 0.02128 0.04255 ... 0.9574 0.9787 1.0 >>> years, datasets = zip(*ds.groupby("time.year")) >>> paths = [f"{y}.nc" for y in years] >>> xr.save_mfdataset(datasets, paths) diff --git a/xarray/coding/cftimeindex.py b/xarray/coding/cftimeindex.py index bddcea97787..9b9dbd7e7aa 100644 --- a/xarray/coding/cftimeindex.py +++ b/xarray/coding/cftimeindex.py @@ -382,30 +382,30 @@ def _partial_date_slice(self, resolution, parsed): ... dims=["time"], ... ) >>> da.sel(time="2001-01-01") - + Size: 8B array([1]) Coordinates: - * time (time) object 2001-01-01 00:00:00 + * time (time) object 8B 2001-01-01 00:00:00 >>> da = xr.DataArray( ... [1, 2], ... coords=[[pd.Timestamp(2001, 1, 1), pd.Timestamp(2001, 2, 1)]], ... dims=["time"], ... ) >>> da.sel(time="2001-01-01") - + Size: 8B array(1) Coordinates: - time datetime64[ns] 2001-01-01 + time datetime64[ns] 8B 2001-01-01 >>> da = xr.DataArray( ... [1, 2], ... coords=[[pd.Timestamp(2001, 1, 1, 1), pd.Timestamp(2001, 2, 1)]], ... dims=["time"], ... ) >>> da.sel(time="2001-01-01") - + Size: 8B array([1]) Coordinates: - * time (time) datetime64[ns] 2001-01-01T01:00:00 + * time (time) datetime64[ns] 8B 2001-01-01T01:00:00 """ start, end = _parsed_string_to_bounds(self.date_type, resolution, parsed) diff --git a/xarray/core/_aggregations.py b/xarray/core/_aggregations.py index e214c2c7c5a..20926dd6b09 100644 --- a/xarray/core/_aggregations.py +++ b/xarray/core/_aggregations.py @@ -83,19 +83,19 @@ def count( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.count() - + Size: 8B Dimensions: () Data variables: - da int64 5 + da int64 8B 5 """ return self.reduce( duck_array_ops.count, @@ -155,19 +155,19 @@ def all( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 78B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.all() - + Size: 1B Dimensions: () Data variables: - da bool False + da bool 1B False """ return self.reduce( duck_array_ops.array_all, @@ -227,19 +227,19 @@ def any( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 78B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.any() - + Size: 1B Dimensions: () Data variables: - da bool True + da bool 1B True """ return self.reduce( duck_array_ops.array_any, @@ -305,27 +305,27 @@ def max( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.max() - + Size: 8B Dimensions: () Data variables: - da float64 3.0 + da float64 8B 3.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.max(skipna=False) - + Size: 8B Dimensions: () Data variables: - da float64 nan + da float64 8B nan """ return self.reduce( duck_array_ops.max, @@ -392,27 +392,27 @@ def min( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.min() - + Size: 8B Dimensions: () Data variables: - da float64 0.0 + da float64 8B 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.min(skipna=False) - + Size: 8B Dimensions: () Data variables: - da float64 nan + da float64 8B nan """ return self.reduce( duck_array_ops.min, @@ -483,27 +483,27 @@ def mean( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.mean() - + Size: 8B Dimensions: () Data variables: - da float64 1.6 + da float64 8B 1.6 Use ``skipna`` to control whether NaNs are ignored. >>> ds.mean(skipna=False) - + Size: 8B Dimensions: () Data variables: - da float64 nan + da float64 8B nan """ return self.reduce( duck_array_ops.mean, @@ -581,35 +581,35 @@ def prod( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.prod() - + Size: 8B Dimensions: () Data variables: - da float64 0.0 + da float64 8B 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.prod(skipna=False) - + Size: 8B Dimensions: () Data variables: - da float64 nan + da float64 8B nan Specify ``min_count`` for finer control over when NaNs are ignored. >>> ds.prod(skipna=True, min_count=2) - + Size: 8B Dimensions: () Data variables: - da float64 0.0 + da float64 8B 0.0 """ return self.reduce( duck_array_ops.prod, @@ -688,35 +688,35 @@ def sum( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.sum() - + Size: 8B Dimensions: () Data variables: - da float64 8.0 + da float64 8B 8.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.sum(skipna=False) - + Size: 8B Dimensions: () Data variables: - da float64 nan + da float64 8B nan Specify ``min_count`` for finer control over when NaNs are ignored. >>> ds.sum(skipna=True, min_count=2) - + Size: 8B Dimensions: () Data variables: - da float64 8.0 + da float64 8B 8.0 """ return self.reduce( duck_array_ops.sum, @@ -792,35 +792,35 @@ def std( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.std() - + Size: 8B Dimensions: () Data variables: - da float64 1.02 + da float64 8B 1.02 Use ``skipna`` to control whether NaNs are ignored. >>> ds.std(skipna=False) - + Size: 8B Dimensions: () Data variables: - da float64 nan + da float64 8B nan Specify ``ddof=1`` for an unbiased estimate. >>> ds.std(skipna=True, ddof=1) - + Size: 8B Dimensions: () Data variables: - da float64 1.14 + da float64 8B 1.14 """ return self.reduce( duck_array_ops.std, @@ -896,35 +896,35 @@ def var( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.var() - + Size: 8B Dimensions: () Data variables: - da float64 1.04 + da float64 8B 1.04 Use ``skipna`` to control whether NaNs are ignored. >>> ds.var(skipna=False) - + Size: 8B Dimensions: () Data variables: - da float64 nan + da float64 8B nan Specify ``ddof=1`` for an unbiased estimate. >>> ds.var(skipna=True, ddof=1) - + Size: 8B Dimensions: () Data variables: - da float64 1.3 + da float64 8B 1.3 """ return self.reduce( duck_array_ops.var, @@ -996,27 +996,27 @@ def median( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.median() - + Size: 8B Dimensions: () Data variables: - da float64 2.0 + da float64 8B 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.median(skipna=False) - + Size: 8B Dimensions: () Data variables: - da float64 nan + da float64 8B nan """ return self.reduce( duck_array_ops.median, @@ -1087,29 +1087,29 @@ def cumsum( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.cumsum() - + Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: - da (time) float64 1.0 3.0 6.0 6.0 8.0 8.0 + da (time) float64 48B 1.0 3.0 6.0 6.0 8.0 8.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.cumsum(skipna=False) - + Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: - da (time) float64 1.0 3.0 6.0 6.0 8.0 nan + da (time) float64 48B 1.0 3.0 6.0 6.0 8.0 nan """ return self.reduce( duck_array_ops.cumsum, @@ -1180,29 +1180,29 @@ def cumprod( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.cumprod() - + Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: - da (time) float64 1.0 2.0 6.0 0.0 0.0 0.0 + da (time) float64 48B 1.0 2.0 6.0 0.0 0.0 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.cumprod(skipna=False) - + Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: - da (time) float64 1.0 2.0 6.0 0.0 0.0 nan + da (time) float64 48B 1.0 2.0 6.0 0.0 0.0 nan """ return self.reduce( duck_array_ops.cumprod, @@ -1278,14 +1278,14 @@ def count( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.count() - + Size: 8B array(5) """ return self.reduce( @@ -1344,14 +1344,14 @@ def all( ... ), ... ) >>> da - + Size: 6B array([ True, True, True, True, True, False]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.all() - + Size: 1B array(False) """ return self.reduce( @@ -1410,14 +1410,14 @@ def any( ... ), ... ) >>> da - + Size: 6B array([ True, True, True, True, True, False]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.any() - + Size: 1B array(True) """ return self.reduce( @@ -1482,20 +1482,20 @@ def max( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.max() - + Size: 8B array(3.) Use ``skipna`` to control whether NaNs are ignored. >>> da.max(skipna=False) - + Size: 8B array(nan) """ return self.reduce( @@ -1561,20 +1561,20 @@ def min( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.min() - + Size: 8B array(0.) Use ``skipna`` to control whether NaNs are ignored. >>> da.min(skipna=False) - + Size: 8B array(nan) """ return self.reduce( @@ -1644,20 +1644,20 @@ def mean( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.mean() - + Size: 8B array(1.6) Use ``skipna`` to control whether NaNs are ignored. >>> da.mean(skipna=False) - + Size: 8B array(nan) """ return self.reduce( @@ -1734,26 +1734,26 @@ def prod( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.prod() - + Size: 8B array(0.) Use ``skipna`` to control whether NaNs are ignored. >>> da.prod(skipna=False) - + Size: 8B array(nan) Specify ``min_count`` for finer control over when NaNs are ignored. >>> da.prod(skipna=True, min_count=2) - + Size: 8B array(0.) """ return self.reduce( @@ -1831,26 +1831,26 @@ def sum( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.sum() - + Size: 8B array(8.) Use ``skipna`` to control whether NaNs are ignored. >>> da.sum(skipna=False) - + Size: 8B array(nan) Specify ``min_count`` for finer control over when NaNs are ignored. >>> da.sum(skipna=True, min_count=2) - + Size: 8B array(8.) """ return self.reduce( @@ -1925,26 +1925,26 @@ def std( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.std() - + Size: 8B array(1.0198039) Use ``skipna`` to control whether NaNs are ignored. >>> da.std(skipna=False) - + Size: 8B array(nan) Specify ``ddof=1`` for an unbiased estimate. >>> da.std(skipna=True, ddof=1) - + Size: 8B array(1.14017543) """ return self.reduce( @@ -2019,26 +2019,26 @@ def var( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.var() - + Size: 8B array(1.04) Use ``skipna`` to control whether NaNs are ignored. >>> da.var(skipna=False) - + Size: 8B array(nan) Specify ``ddof=1`` for an unbiased estimate. >>> da.var(skipna=True, ddof=1) - + Size: 8B array(1.3) """ return self.reduce( @@ -2109,20 +2109,20 @@ def median( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.median() - + Size: 8B array(2.) Use ``skipna`` to control whether NaNs are ignored. >>> da.median(skipna=False) - + Size: 8B array(nan) """ return self.reduce( @@ -2192,27 +2192,27 @@ def cumsum( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.cumsum() - + Size: 48B array([1., 3., 6., 6., 8., 8.]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.cumsum(skipna=False) - + Size: 48B array([ 1., 3., 6., 6., 8., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.cumprod() - + Size: 48B array([1., 2., 6., 0., 0., 0.]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.cumprod(skipna=False) - + Size: 48B array([ 1., 2., 6., 0., 0., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").count() - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) int64 1 2 2 + da (labels) int64 24B 1 2 2 """ if ( flox_available @@ -2505,21 +2505,21 @@ def all( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 78B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").all() - + Size: 27B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) bool False True True + da (labels) bool 3B False True True """ if ( flox_available @@ -2603,21 +2603,21 @@ def any( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 78B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").any() - + Size: 27B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) bool True True True + da (labels) bool 3B True True True """ if ( flox_available @@ -2707,31 +2707,31 @@ def max( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").max() - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 1.0 2.0 3.0 + da (labels) float64 24B 1.0 2.0 3.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").max(skipna=False) - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 nan 2.0 3.0 + da (labels) float64 24B nan 2.0 3.0 """ if ( flox_available @@ -2823,31 +2823,31 @@ def min( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").min() - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 1.0 2.0 0.0 + da (labels) float64 24B 1.0 2.0 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").min(skipna=False) - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 nan 2.0 0.0 + da (labels) float64 24B nan 2.0 0.0 """ if ( flox_available @@ -2941,31 +2941,31 @@ def mean( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").mean() - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 1.0 2.0 1.5 + da (labels) float64 24B 1.0 2.0 1.5 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").mean(skipna=False) - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 nan 2.0 1.5 + da (labels) float64 24B nan 2.0 1.5 """ if ( flox_available @@ -3066,41 +3066,41 @@ def prod( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").prod() - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 1.0 4.0 0.0 + da (labels) float64 24B 1.0 4.0 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").prod(skipna=False) - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 nan 4.0 0.0 + da (labels) float64 24B nan 4.0 0.0 Specify ``min_count`` for finer control over when NaNs are ignored. >>> ds.groupby("labels").prod(skipna=True, min_count=2) - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 nan 4.0 0.0 + da (labels) float64 24B nan 4.0 0.0 """ if ( flox_available @@ -3203,41 +3203,41 @@ def sum( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").sum() - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 1.0 4.0 3.0 + da (labels) float64 24B 1.0 4.0 3.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").sum(skipna=False) - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 nan 4.0 3.0 + da (labels) float64 24B nan 4.0 3.0 Specify ``min_count`` for finer control over when NaNs are ignored. >>> ds.groupby("labels").sum(skipna=True, min_count=2) - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 nan 4.0 3.0 + da (labels) float64 24B nan 4.0 3.0 """ if ( flox_available @@ -3337,41 +3337,41 @@ def std( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").std() - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 0.0 0.0 1.5 + da (labels) float64 24B 0.0 0.0 1.5 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").std(skipna=False) - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 nan 0.0 1.5 + da (labels) float64 24B nan 0.0 1.5 Specify ``ddof=1`` for an unbiased estimate. >>> ds.groupby("labels").std(skipna=True, ddof=1) - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 nan 0.0 2.121 + da (labels) float64 24B nan 0.0 2.121 """ if ( flox_available @@ -3471,41 +3471,41 @@ def var( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").var() - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 0.0 0.0 2.25 + da (labels) float64 24B 0.0 0.0 2.25 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").var(skipna=False) - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 nan 0.0 2.25 + da (labels) float64 24B nan 0.0 2.25 Specify ``ddof=1`` for an unbiased estimate. >>> ds.groupby("labels").var(skipna=True, ddof=1) - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 nan 0.0 4.5 + da (labels) float64 24B nan 0.0 4.5 """ if ( flox_available @@ -3601,31 +3601,31 @@ def median( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").median() - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 1.0 2.0 1.5 + da (labels) float64 24B 1.0 2.0 1.5 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").median(skipna=False) - + Size: 48B Dimensions: (labels: 3) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Data variables: - da (labels) float64 nan 2.0 1.5 + da (labels) float64 24B nan 2.0 1.5 """ return self._reduce_without_squeeze_warn( duck_array_ops.median, @@ -3704,29 +3704,29 @@ def cumsum( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").cumsum() - + Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: - da (time) float64 1.0 2.0 3.0 3.0 4.0 1.0 + da (time) float64 48B 1.0 2.0 3.0 3.0 4.0 1.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").cumsum(skipna=False) - + Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: - da (time) float64 1.0 2.0 3.0 3.0 4.0 nan + da (time) float64 48B 1.0 2.0 3.0 3.0 4.0 nan """ return self._reduce_without_squeeze_warn( duck_array_ops.cumsum, @@ -3805,29 +3805,29 @@ def cumprod( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.groupby("labels").cumprod() - + Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: - da (time) float64 1.0 2.0 3.0 0.0 4.0 1.0 + da (time) float64 48B 1.0 2.0 3.0 0.0 4.0 1.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.groupby("labels").cumprod(skipna=False) - + Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: - da (time) float64 1.0 2.0 3.0 0.0 4.0 nan + da (time) float64 48B 1.0 2.0 3.0 0.0 4.0 nan """ return self._reduce_without_squeeze_warn( duck_array_ops.cumprod, @@ -3934,21 +3934,21 @@ def count( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").count() - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) int64 1 3 1 + da (time) int64 24B 1 3 1 """ if ( flox_available @@ -4032,21 +4032,21 @@ def all( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 78B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").all() - + Size: 27B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) bool True True False + da (time) bool 3B True True False """ if ( flox_available @@ -4130,21 +4130,21 @@ def any( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 78B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").any() - + Size: 27B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) bool True True True + da (time) bool 3B True True True """ if ( flox_available @@ -4234,31 +4234,31 @@ def max( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").max() - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 1.0 3.0 2.0 + da (time) float64 24B 1.0 3.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").max(skipna=False) - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 1.0 3.0 nan + da (time) float64 24B 1.0 3.0 nan """ if ( flox_available @@ -4350,31 +4350,31 @@ def min( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").min() - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 1.0 0.0 2.0 + da (time) float64 24B 1.0 0.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").min(skipna=False) - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 1.0 0.0 nan + da (time) float64 24B 1.0 0.0 nan """ if ( flox_available @@ -4468,31 +4468,31 @@ def mean( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").mean() - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 1.0 1.667 2.0 + da (time) float64 24B 1.0 1.667 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").mean(skipna=False) - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 1.0 1.667 nan + da (time) float64 24B 1.0 1.667 nan """ if ( flox_available @@ -4593,41 +4593,41 @@ def prod( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").prod() - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 1.0 0.0 2.0 + da (time) float64 24B 1.0 0.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").prod(skipna=False) - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 1.0 0.0 nan + da (time) float64 24B 1.0 0.0 nan Specify ``min_count`` for finer control over when NaNs are ignored. >>> ds.resample(time="3ME").prod(skipna=True, min_count=2) - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 nan 0.0 nan + da (time) float64 24B nan 0.0 nan """ if ( flox_available @@ -4730,41 +4730,41 @@ def sum( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").sum() - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 1.0 5.0 2.0 + da (time) float64 24B 1.0 5.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").sum(skipna=False) - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 1.0 5.0 nan + da (time) float64 24B 1.0 5.0 nan Specify ``min_count`` for finer control over when NaNs are ignored. >>> ds.resample(time="3ME").sum(skipna=True, min_count=2) - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 nan 5.0 nan + da (time) float64 24B nan 5.0 nan """ if ( flox_available @@ -4864,41 +4864,41 @@ def std( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").std() - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 0.0 1.247 0.0 + da (time) float64 24B 0.0 1.247 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").std(skipna=False) - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 0.0 1.247 nan + da (time) float64 24B 0.0 1.247 nan Specify ``ddof=1`` for an unbiased estimate. >>> ds.resample(time="3ME").std(skipna=True, ddof=1) - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 nan 1.528 nan + da (time) float64 24B nan 1.528 nan """ if ( flox_available @@ -4998,41 +4998,41 @@ def var( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").var() - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 0.0 1.556 0.0 + da (time) float64 24B 0.0 1.556 0.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").var(skipna=False) - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 0.0 1.556 nan + da (time) float64 24B 0.0 1.556 nan Specify ``ddof=1`` for an unbiased estimate. >>> ds.resample(time="3ME").var(skipna=True, ddof=1) - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 nan 2.333 nan + da (time) float64 24B nan 2.333 nan """ if ( flox_available @@ -5128,31 +5128,31 @@ def median( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").median() - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 1.0 2.0 2.0 + da (time) float64 24B 1.0 2.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").median(skipna=False) - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Data variables: - da (time) float64 1.0 2.0 nan + da (time) float64 24B 1.0 2.0 nan """ return self._reduce_without_squeeze_warn( duck_array_ops.median, @@ -5231,29 +5231,29 @@ def cumsum( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").cumsum() - + Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: - da (time) float64 1.0 2.0 5.0 5.0 2.0 2.0 + da (time) float64 48B 1.0 2.0 5.0 5.0 2.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").cumsum(skipna=False) - + Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: - da (time) float64 1.0 2.0 5.0 5.0 2.0 nan + da (time) float64 48B 1.0 2.0 5.0 5.0 2.0 nan """ return self._reduce_without_squeeze_warn( duck_array_ops.cumsum, @@ -5332,29 +5332,29 @@ def cumprod( ... ) >>> ds = xr.Dataset(dict(da=da)) >>> ds - + Size: 120B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> ds.resample(time="3ME").cumprod() - + Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: - da (time) float64 1.0 2.0 6.0 0.0 2.0 2.0 + da (time) float64 48B 1.0 2.0 6.0 0.0 2.0 2.0 Use ``skipna`` to control whether NaNs are ignored. >>> ds.resample(time="3ME").cumprod(skipna=False) - + Size: 48B Dimensions: (time: 6) Dimensions without coordinates: time Data variables: - da (time) float64 1.0 2.0 6.0 0.0 2.0 nan + da (time) float64 48B 1.0 2.0 6.0 0.0 2.0 nan """ return self._reduce_without_squeeze_warn( duck_array_ops.cumprod, @@ -5460,17 +5460,17 @@ def count( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").count() - + Size: 24B array([1, 2, 2]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -5551,17 +5551,17 @@ def all( ... ), ... ) >>> da - + Size: 6B array([ True, True, True, True, True, False]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").all() - + Size: 3B array([False, True, True]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -5642,17 +5642,17 @@ def any( ... ), ... ) >>> da - + Size: 6B array([ True, True, True, True, True, False]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").any() - + Size: 3B array([ True, True, True]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -5739,25 +5739,25 @@ def max( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").max() - + Size: 24B array([1., 2., 3.]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").max(skipna=False) - + Size: 24B array([nan, 2., 3.]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -5846,25 +5846,25 @@ def min( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").min() - + Size: 24B array([1., 2., 0.]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").min(skipna=False) - + Size: 24B array([nan, 2., 0.]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -5955,25 +5955,25 @@ def mean( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").mean() - + Size: 24B array([1. , 2. , 1.5]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").mean(skipna=False) - + Size: 24B array([nan, 2. , 1.5]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6071,33 +6071,33 @@ def prod( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").prod() - + Size: 24B array([1., 4., 0.]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").prod(skipna=False) - + Size: 24B array([nan, 4., 0.]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Specify ``min_count`` for finer control over when NaNs are ignored. >>> da.groupby("labels").prod(skipna=True, min_count=2) - + Size: 24B array([nan, 4., 0.]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6197,33 +6197,33 @@ def sum( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").sum() - + Size: 24B array([1., 4., 3.]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").sum(skipna=False) - + Size: 24B array([nan, 4., 3.]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Specify ``min_count`` for finer control over when NaNs are ignored. >>> da.groupby("labels").sum(skipna=True, min_count=2) - + Size: 24B array([nan, 4., 3.]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6320,33 +6320,33 @@ def std( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").std() - + Size: 24B array([0. , 0. , 1.5]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").std(skipna=False) - + Size: 24B array([nan, 0. , 1.5]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Specify ``ddof=1`` for an unbiased estimate. >>> da.groupby("labels").std(skipna=True, ddof=1) - + Size: 24B array([ nan, 0. , 2.12132034]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6443,33 +6443,33 @@ def var( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").var() - + Size: 24B array([0. , 0. , 2.25]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").var(skipna=False) - + Size: 24B array([ nan, 0. , 2.25]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Specify ``ddof=1`` for an unbiased estimate. >>> da.groupby("labels").var(skipna=True, ddof=1) - + Size: 24B array([nan, 0. , 4.5]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' """ if ( flox_available @@ -6562,25 +6562,25 @@ def median( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").median() - + Size: 24B array([1. , 2. , 1.5]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' Use ``skipna`` to control whether NaNs are ignored. >>> da.groupby("labels").median(skipna=False) - + Size: 24B array([nan, 2. , 1.5]) Coordinates: - * labels (labels) object 'a' 'b' 'c' + * labels (labels) object 24B 'a' 'b' 'c' """ return self._reduce_without_squeeze_warn( duck_array_ops.median, @@ -6657,27 +6657,27 @@ def cumsum( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").cumsum() - + Size: 48B array([1., 2., 3., 3., 4., 1.]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").cumsum(skipna=False) - + Size: 48B array([ 1., 2., 3., 3., 4., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").cumprod() - + Size: 48B array([1., 2., 3., 0., 4., 1.]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.groupby("labels").cumprod(skipna=False) - + Size: 48B array([ 1., 2., 3., 0., 4., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").count() - + Size: 24B array([1, 3, 1]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -6970,17 +6970,17 @@ def all( ... ), ... ) >>> da - + Size: 6B array([ True, True, True, True, True, False]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").all() - + Size: 3B array([ True, True, False]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7061,17 +7061,17 @@ def any( ... ), ... ) >>> da - + Size: 6B array([ True, True, True, True, True, False]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").any() - + Size: 3B array([ True, True, True]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7158,25 +7158,25 @@ def max( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").max() - + Size: 24B array([1., 3., 2.]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").max(skipna=False) - + Size: 24B array([ 1., 3., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7265,25 +7265,25 @@ def min( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").min() - + Size: 24B array([1., 0., 2.]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").min(skipna=False) - + Size: 24B array([ 1., 0., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7374,25 +7374,25 @@ def mean( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").mean() - + Size: 24B array([1. , 1.66666667, 2. ]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").mean(skipna=False) - + Size: 24B array([1. , 1.66666667, nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7490,33 +7490,33 @@ def prod( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").prod() - + Size: 24B array([1., 0., 2.]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").prod(skipna=False) - + Size: 24B array([ 1., 0., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Specify ``min_count`` for finer control over when NaNs are ignored. >>> da.resample(time="3ME").prod(skipna=True, min_count=2) - + Size: 24B array([nan, 0., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7616,33 +7616,33 @@ def sum( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").sum() - + Size: 24B array([1., 5., 2.]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").sum(skipna=False) - + Size: 24B array([ 1., 5., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Specify ``min_count`` for finer control over when NaNs are ignored. >>> da.resample(time="3ME").sum(skipna=True, min_count=2) - + Size: 24B array([nan, 5., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7739,33 +7739,33 @@ def std( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").std() - + Size: 24B array([0. , 1.24721913, 0. ]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").std(skipna=False) - + Size: 24B array([0. , 1.24721913, nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Specify ``ddof=1`` for an unbiased estimate. >>> da.resample(time="3ME").std(skipna=True, ddof=1) - + Size: 24B array([ nan, 1.52752523, nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7862,33 +7862,33 @@ def var( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").var() - + Size: 24B array([0. , 1.55555556, 0. ]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").var(skipna=False) - + Size: 24B array([0. , 1.55555556, nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Specify ``ddof=1`` for an unbiased estimate. >>> da.resample(time="3ME").var(skipna=True, ddof=1) - + Size: 24B array([ nan, 2.33333333, nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ if ( flox_available @@ -7981,25 +7981,25 @@ def median( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").median() - + Size: 24B array([1., 2., 2.]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 Use ``skipna`` to control whether NaNs are ignored. >>> da.resample(time="3ME").median(skipna=False) - + Size: 24B array([ 1., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-04-30 2001-07-31 + * time (time) datetime64[ns] 24B 2001-01-31 2001-04-30 2001-07-31 """ return self._reduce_without_squeeze_warn( duck_array_ops.median, @@ -8076,26 +8076,26 @@ def cumsum( ... ), ... ) >>> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").cumsum() - + Size: 48B array([1., 2., 5., 5., 2., 2.]) Coordinates: - labels (time) >> da.resample(time="3ME").cumsum(skipna=False) - + Size: 48B array([ 1., 2., 5., 5., 2., nan]) Coordinates: - labels (time) >> da - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) Coordinates: - * time (time) datetime64[ns] 2001-01-31 2001-02-28 ... 2001-06-30 - labels (time) >> da.resample(time="3ME").cumprod() - + Size: 48B array([1., 2., 6., 0., 2., 2.]) Coordinates: - labels (time) >> da.resample(time="3ME").cumprod(skipna=False) - + Size: 48B array([ 1., 2., 6., 0., 2., nan]) Coordinates: - labels (time) >> dates = pd.date_range(start="2000/01/01", freq="D", periods=10) >>> ts = xr.DataArray(dates, dims=("time")) >>> ts - + Size: 80B array(['2000-01-01T00:00:00.000000000', '2000-01-02T00:00:00.000000000', '2000-01-03T00:00:00.000000000', '2000-01-04T00:00:00.000000000', '2000-01-05T00:00:00.000000000', '2000-01-06T00:00:00.000000000', @@ -321,19 +321,19 @@ class DatetimeAccessor(TimeAccessor[T_DataArray]): '2000-01-09T00:00:00.000000000', '2000-01-10T00:00:00.000000000'], dtype='datetime64[ns]') Coordinates: - * time (time) datetime64[ns] 2000-01-01 2000-01-02 ... 2000-01-10 + * time (time) datetime64[ns] 80B 2000-01-01 2000-01-02 ... 2000-01-10 >>> ts.dt # doctest: +ELLIPSIS >>> ts.dt.dayofyear - + Size: 80B array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) Coordinates: - * time (time) datetime64[ns] 2000-01-01 2000-01-02 ... 2000-01-10 + * time (time) datetime64[ns] 80B 2000-01-01 2000-01-02 ... 2000-01-10 >>> ts.dt.quarter - + Size: 80B array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) Coordinates: - * time (time) datetime64[ns] 2000-01-01 2000-01-02 ... 2000-01-10 + * time (time) datetime64[ns] 80B 2000-01-01 2000-01-02 ... 2000-01-10 """ @@ -359,7 +359,7 @@ def strftime(self, date_format: str) -> T_DataArray: >>> import datetime >>> rng = xr.Dataset({"time": datetime.datetime(2000, 1, 1)}) >>> rng["time"].dt.strftime("%B %d, %Y, %r") - + Size: 8B array('January 01, 2000, 12:00:00 AM', dtype=object) """ obj_type = type(self._obj) @@ -544,7 +544,7 @@ class TimedeltaAccessor(TimeAccessor[T_DataArray]): >>> dates = pd.timedelta_range(start="1 day", freq="6h", periods=20) >>> ts = xr.DataArray(dates, dims=("time")) >>> ts - + Size: 160B array([ 86400000000000, 108000000000000, 129600000000000, 151200000000000, 172800000000000, 194400000000000, 216000000000000, 237600000000000, 259200000000000, 280800000000000, 302400000000000, 324000000000000, @@ -552,33 +552,33 @@ class TimedeltaAccessor(TimeAccessor[T_DataArray]): 432000000000000, 453600000000000, 475200000000000, 496800000000000], dtype='timedelta64[ns]') Coordinates: - * time (time) timedelta64[ns] 1 days 00:00:00 ... 5 days 18:00:00 + * time (time) timedelta64[ns] 160B 1 days 00:00:00 ... 5 days 18:00:00 >>> ts.dt # doctest: +ELLIPSIS >>> ts.dt.days - + Size: 160B array([1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5]) Coordinates: - * time (time) timedelta64[ns] 1 days 00:00:00 ... 5 days 18:00:00 + * time (time) timedelta64[ns] 160B 1 days 00:00:00 ... 5 days 18:00:00 >>> ts.dt.microseconds - + Size: 160B array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) Coordinates: - * time (time) timedelta64[ns] 1 days 00:00:00 ... 5 days 18:00:00 + * time (time) timedelta64[ns] 160B 1 days 00:00:00 ... 5 days 18:00:00 >>> ts.dt.seconds - + Size: 160B array([ 0, 21600, 43200, 64800, 0, 21600, 43200, 64800, 0, 21600, 43200, 64800, 0, 21600, 43200, 64800, 0, 21600, 43200, 64800]) Coordinates: - * time (time) timedelta64[ns] 1 days 00:00:00 ... 5 days 18:00:00 + * time (time) timedelta64[ns] 160B 1 days 00:00:00 ... 5 days 18:00:00 >>> ts.dt.total_seconds() - + Size: 160B array([ 86400., 108000., 129600., 151200., 172800., 194400., 216000., 237600., 259200., 280800., 302400., 324000., 345600., 367200., 388800., 410400., 432000., 453600., 475200., 496800.]) Coordinates: - * time (time) timedelta64[ns] 1 days 00:00:00 ... 5 days 18:00:00 + * time (time) timedelta64[ns] 160B 1 days 00:00:00 ... 5 days 18:00:00 """ @property diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 573200b5c88..762f21aed4b 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -148,7 +148,7 @@ class StringAccessor(Generic[T_DataArray]): >>> da = xr.DataArray(["some", "text", "in", "an", "array"]) >>> da.str.len() - + Size: 40B array([4, 4, 2, 2, 5]) Dimensions without coordinates: dim_0 @@ -159,7 +159,7 @@ class StringAccessor(Generic[T_DataArray]): >>> da1 = xr.DataArray(["first", "second", "third"], dims=["X"]) >>> da2 = xr.DataArray([1, 2, 3], dims=["Y"]) >>> da1.str + da2 - + Size: 252B array([['first1', 'first2', 'first3'], ['second1', 'second2', 'second3'], ['third1', 'third2', 'third3']], dtype='>> da1 = xr.DataArray(["a", "b", "c", "d"], dims=["X"]) >>> reps = xr.DataArray([3, 4], dims=["Y"]) >>> da1.str * reps - + Size: 128B array([['aaa', 'aaaa'], ['bbb', 'bbbb'], ['ccc', 'cccc'], @@ -179,7 +179,7 @@ class StringAccessor(Generic[T_DataArray]): >>> da2 = xr.DataArray([1, 2], dims=["Y"]) >>> da3 = xr.DataArray([0.1, 0.2], dims=["Z"]) >>> da1.str % (da2, da3) - + Size: 240B array([[['1_0.1', '1_0.2'], ['2_0.1', '2_0.2']], @@ -197,8 +197,8 @@ class StringAccessor(Generic[T_DataArray]): >>> da1 = xr.DataArray(["%(a)s"], dims=["X"]) >>> da2 = xr.DataArray([1, 2, 3], dims=["Y"]) >>> da1 % {"a": da2} - - array(['\narray([1, 2, 3])\nDimensions without coordinates: Y'], + Size: 8B + array([' Size: 24B\narray([1, 2, 3])\nDimensions without coordinates: Y'], dtype=object) Dimensions without coordinates: X """ @@ -483,7 +483,7 @@ def cat(self, *others, sep: str | bytes | Any = "") -> T_DataArray: Concatenate the arrays using the separator >>> myarray.str.cat(values_1, values_2, values_3, values_4, sep=seps) - + Size: 1kB array([[['11111 a 3.4 test', '11111, a, 3.4, , test'], ['11111 bb 3.4 test', '11111, bb, 3.4, , test'], ['11111 cccc 3.4 test', '11111, cccc, 3.4, , test']], @@ -556,7 +556,7 @@ def join( Join the strings along a given dimension >>> values.str.join(dim="Y", sep=seps) - + Size: 192B array([['a-bab-abc', 'a_bab_abc'], ['abcd--abcdef', 'abcd__abcdef']], dtype='>> values.str.format(noun0, noun1, adj0=adj0, adj1=adj1) - + Size: 1kB array([[['spam is unexpected', 'spam is unexpected'], ['egg is unexpected', 'egg is unexpected']], @@ -680,13 +680,13 @@ def capitalize(self) -> T_DataArray: ... ["temperature", "PRESSURE", "PreCipiTation", "daily rainfall"], dims="x" ... ) >>> da - + Size: 224B array(['temperature', 'PRESSURE', 'PreCipiTation', 'daily rainfall'], dtype='>> capitalized = da.str.capitalize() >>> capitalized - + Size: 224B array(['Temperature', 'Pressure', 'Precipitation', 'Daily rainfall'], dtype=' T_DataArray: -------- >>> da = xr.DataArray(["Temperature", "PRESSURE"], dims="x") >>> da - + Size: 88B array(['Temperature', 'PRESSURE'], dtype='>> lowered = da.str.lower() >>> lowered - + Size: 88B array(['temperature', 'pressure'], dtype=' T_DataArray: >>> import xarray as xr >>> da = xr.DataArray(["temperature", "PRESSURE", "HuMiDiTy"], dims="x") >>> da - + Size: 132B array(['temperature', 'PRESSURE', 'HuMiDiTy'], dtype='>> swapcased = da.str.swapcase() >>> swapcased - + Size: 132B array(['TEMPERATURE', 'pressure', 'hUmIdItY'], dtype=' T_DataArray: -------- >>> da = xr.DataArray(["temperature", "PRESSURE", "HuMiDiTy"], dims="x") >>> da - + Size: 132B array(['temperature', 'PRESSURE', 'HuMiDiTy'], dtype='>> titled = da.str.title() >>> titled - + Size: 132B array(['Temperature', 'Pressure', 'Humidity'], dtype=' T_DataArray: -------- >>> da = xr.DataArray(["temperature", "HuMiDiTy"], dims="x") >>> da - + Size: 88B array(['temperature', 'HuMiDiTy'], dtype='>> uppered = da.str.upper() >>> uppered - + Size: 88B array(['TEMPERATURE', 'HUMIDITY'], dtype=' T_DataArray: -------- >>> da = xr.DataArray(["TEMPERATURE", "HuMiDiTy"], dims="x") >>> da - + Size: 88B array(['TEMPERATURE', 'HuMiDiTy'], dtype='>> casefolded = da.str.casefold() >>> casefolded - + Size: 88B array(['temperature', 'humidity'], dtype='>> da = xr.DataArray(["ß", "İ"], dims="x") >>> da - + Size: 8B array(['ß', 'İ'], dtype='>> casefolded = da.str.casefold() >>> casefolded - + Size: 16B array(['ss', 'i̇'], dtype=' T_DataArray: -------- >>> da = xr.DataArray(["H2O", "NaCl-"], dims="x") >>> da - + Size: 40B array(['H2O', 'NaCl-'], dtype='>> isalnum = da.str.isalnum() >>> isalnum - + Size: 2B array([ True, False]) Dimensions without coordinates: x """ @@ -886,12 +886,12 @@ def isalpha(self) -> T_DataArray: -------- >>> da = xr.DataArray(["Mn", "H2O", "NaCl-"], dims="x") >>> da - + Size: 60B array(['Mn', 'H2O', 'NaCl-'], dtype='>> isalpha = da.str.isalpha() >>> isalpha - + Size: 3B array([ True, False, False]) Dimensions without coordinates: x """ @@ -910,12 +910,12 @@ def isdecimal(self) -> T_DataArray: -------- >>> da = xr.DataArray(["2.3", "123", "0"], dims="x") >>> da - + Size: 36B array(['2.3', '123', '0'], dtype='>> isdecimal = da.str.isdecimal() >>> isdecimal - + Size: 3B array([False, True, True]) Dimensions without coordinates: x """ @@ -934,12 +934,12 @@ def isdigit(self) -> T_DataArray: -------- >>> da = xr.DataArray(["123", "1.2", "0", "CO2", "NaCl"], dims="x") >>> da - + Size: 80B array(['123', '1.2', '0', 'CO2', 'NaCl'], dtype='>> isdigit = da.str.isdigit() >>> isdigit - + Size: 5B array([ True, False, True, False, False]) Dimensions without coordinates: x """ @@ -959,12 +959,12 @@ def islower(self) -> T_DataArray: -------- >>> da = xr.DataArray(["temperature", "HUMIDITY", "pREciPiTaTioN"], dims="x") >>> da - + Size: 156B array(['temperature', 'HUMIDITY', 'pREciPiTaTioN'], dtype='>> islower = da.str.islower() >>> islower - + Size: 3B array([ True, False, False]) Dimensions without coordinates: x """ @@ -983,12 +983,12 @@ def isnumeric(self) -> T_DataArray: -------- >>> da = xr.DataArray(["123", "2.3", "H2O", "NaCl-", "Mn"], dims="x") >>> da - + Size: 100B array(['123', '2.3', 'H2O', 'NaCl-', 'Mn'], dtype='>> isnumeric = da.str.isnumeric() >>> isnumeric - + Size: 5B array([ True, False, False, False, False]) Dimensions without coordinates: x """ @@ -1007,12 +1007,12 @@ def isspace(self) -> T_DataArray: -------- >>> da = xr.DataArray(["", " ", "\\t", "\\n"], dims="x") >>> da - - array(['', ' ', '\\t', '\\n'], dtype=' Size: 16B + array(['', ' ', '\t', '\n'], dtype='>> isspace = da.str.isspace() >>> isspace - + Size: 4B array([False, True, True, True]) Dimensions without coordinates: x """ @@ -1038,13 +1038,13 @@ def istitle(self) -> T_DataArray: ... dims="title", ... ) >>> da - + Size: 360B array(['The Evolution Of Species', 'The Theory of relativity', 'the quantum mechanics of atoms'], dtype='>> istitle = da.str.istitle() >>> istitle - + Size: 3B array([ True, False, False]) Dimensions without coordinates: title """ @@ -1063,12 +1063,12 @@ def isupper(self) -> T_DataArray: -------- >>> da = xr.DataArray(["TEMPERATURE", "humidity", "PreCIpiTAtioN"], dims="x") >>> da - + Size: 156B array(['TEMPERATURE', 'humidity', 'PreCIpiTAtioN'], dtype='>> isupper = da.str.isupper() >>> isupper - + Size: 3B array([ True, False, False]) Dimensions without coordinates: x """ @@ -1111,20 +1111,20 @@ def count( -------- >>> da = xr.DataArray(["jjklmn", "opjjqrs", "t-JJ99vwx"], dims="x") >>> da - + Size: 108B array(['jjklmn', 'opjjqrs', 't-JJ99vwx'], dtype='>> da.str.count("jj") - + Size: 24B array([1, 1, 0]) Dimensions without coordinates: x Enable case-insensitive matching by setting case to false: >>> counts = da.str.count("jj", case=False) >>> counts - + Size: 24B array([1, 1, 1]) Dimensions without coordinates: x @@ -1132,7 +1132,7 @@ def count( >>> pat = "JJ[0-9]{2}[a-z]{3}" >>> counts = da.str.count(pat) >>> counts - + Size: 24B array([0, 0, 1]) Dimensions without coordinates: x @@ -1141,7 +1141,7 @@ def count( >>> pat = xr.DataArray(["jj", "JJ"], dims="y") >>> counts = da.str.count(pat) >>> counts - + Size: 48B array([[1, 0], [1, 0], [0, 1]]) @@ -1175,12 +1175,12 @@ def startswith(self, pat: str | bytes | Any) -> T_DataArray: -------- >>> da = xr.DataArray(["$100", "£23", "100"], dims="x") >>> da - + Size: 48B array(['$100', '£23', '100'], dtype='>> startswith = da.str.startswith("$") >>> startswith - + Size: 3B array([ True, False, False]) Dimensions without coordinates: x """ @@ -1211,12 +1211,12 @@ def endswith(self, pat: str | bytes | Any) -> T_DataArray: -------- >>> da = xr.DataArray(["10C", "10c", "100F"], dims="x") >>> da - + Size: 48B array(['10C', '10c', '100F'], dtype='>> endswith = da.str.endswith("C") >>> endswith - + Size: 3B array([ True, False, False]) Dimensions without coordinates: x """ @@ -1261,7 +1261,7 @@ def pad( >>> da = xr.DataArray(["PAR184", "TKO65", "NBO9139", "NZ39"], dims="x") >>> da - + Size: 112B array(['PAR184', 'TKO65', 'NBO9139', 'NZ39'], dtype='>> filled = da.str.pad(8, side="left", fillchar="0") >>> filled - + Size: 128B array(['00PAR184', '000TKO65', '0NBO9139', '0000NZ39'], dtype='>> filled = da.str.pad(8, side="right", fillchar="0") >>> filled - + Size: 128B array(['PAR18400', 'TKO65000', 'NBO91390', 'NZ390000'], dtype='>> filled = da.str.pad(8, side="both", fillchar="0") >>> filled - + Size: 128B array(['0PAR1840', '0TKO6500', 'NBO91390', '00NZ3900'], dtype='>> width = xr.DataArray([8, 10], dims="y") >>> filled = da.str.pad(width, side="left", fillchar="0") >>> filled - + Size: 320B array([['00PAR184', '0000PAR184'], ['000TKO65', '00000TKO65'], ['0NBO9139', '000NBO9139'], @@ -1306,7 +1306,7 @@ def pad( >>> fillchar = xr.DataArray(["0", "-"], dims="y") >>> filled = da.str.pad(8, side="left", fillchar=fillchar) >>> filled - + Size: 256B array([['00PAR184', '--PAR184'], ['000TKO65', '---TKO65'], ['0NBO9139', '-NBO9139'], @@ -2024,7 +2024,7 @@ def extract( Extract matches >>> value.str.extract(r"(\w+)_Xy_(\d*)", dim="match") - + Size: 288B array([[['a', '0'], ['bab', '110'], ['abc', '01']], @@ -2178,7 +2178,7 @@ def extractall( >>> value.str.extractall( ... r"(\w+)_Xy_(\d*)", group_dim="group", match_dim="match" ... ) - + Size: 1kB array([[[['a', '0'], ['', ''], ['', '']], @@ -2342,7 +2342,7 @@ def findall( Extract matches >>> value.str.findall(r"(\w+)_Xy_(\d*)") - + Size: 48B array([[list([('a', '0')]), list([('bab', '110'), ('baab', '1100')]), list([('abc', '01'), ('cbc', '2210')])], [list([('abcd', ''), ('dcd', '33210'), ('dccd', '332210')]), @@ -2577,7 +2577,7 @@ def split( Split once and put the results in a new dimension >>> values.str.split(dim="splitted", maxsplit=1) - + Size: 864B array([[['abc', 'def'], ['spam', 'eggs\tswallow'], ['red_blue', '']], @@ -2590,7 +2590,7 @@ def split( Split as many times as needed and put the results in a new dimension >>> values.str.split(dim="splitted") - + Size: 768B array([[['abc', 'def', '', ''], ['spam', 'eggs', 'swallow', ''], ['red_blue', '', '', '']], @@ -2603,7 +2603,7 @@ def split( Split once and put the results in lists >>> values.str.split(dim=None, maxsplit=1) - + Size: 48B array([[list(['abc', 'def']), list(['spam', 'eggs\tswallow']), list(['red_blue'])], [list(['test0', 'test1\ntest2\n\ntest3']), list([]), @@ -2613,7 +2613,7 @@ def split( Split as many times as needed and put the results in a list >>> values.str.split(dim=None) - + Size: 48B array([[list(['abc', 'def']), list(['spam', 'eggs', 'swallow']), list(['red_blue'])], [list(['test0', 'test1', 'test2', 'test3']), list([]), @@ -2623,7 +2623,7 @@ def split( Split only on spaces >>> values.str.split(dim="splitted", sep=" ") - + Size: 2kB array([[['abc', 'def', ''], ['spam\t\teggs\tswallow', '', ''], ['red_blue', '', '']], @@ -2695,7 +2695,7 @@ def rsplit( Split once and put the results in a new dimension >>> values.str.rsplit(dim="splitted", maxsplit=1) - + Size: 816B array([[['abc', 'def'], ['spam\t\teggs', 'swallow'], ['', 'red_blue']], @@ -2708,7 +2708,7 @@ def rsplit( Split as many times as needed and put the results in a new dimension >>> values.str.rsplit(dim="splitted") - + Size: 768B array([[['', '', 'abc', 'def'], ['', 'spam', 'eggs', 'swallow'], ['', '', '', 'red_blue']], @@ -2721,7 +2721,7 @@ def rsplit( Split once and put the results in lists >>> values.str.rsplit(dim=None, maxsplit=1) - + Size: 48B array([[list(['abc', 'def']), list(['spam\t\teggs', 'swallow']), list(['red_blue'])], [list(['test0\ntest1\ntest2', 'test3']), list([]), @@ -2731,7 +2731,7 @@ def rsplit( Split as many times as needed and put the results in a list >>> values.str.rsplit(dim=None) - + Size: 48B array([[list(['abc', 'def']), list(['spam', 'eggs', 'swallow']), list(['red_blue'])], [list(['test0', 'test1', 'test2', 'test3']), list([]), @@ -2741,7 +2741,7 @@ def rsplit( Split only on spaces >>> values.str.rsplit(dim="splitted", sep=" ") - + Size: 2kB array([[['', 'abc', 'def'], ['', '', 'spam\t\teggs\tswallow'], ['', '', 'red_blue']], @@ -2808,7 +2808,7 @@ def get_dummies( Extract dummy values >>> values.str.get_dummies(dim="dummies") - + Size: 30B array([[[ True, False, True, False, True], [False, True, False, False, False], [ True, False, True, True, False]], @@ -2817,7 +2817,7 @@ def get_dummies( [False, False, True, False, True], [ True, False, False, False, False]]]) Coordinates: - * dummies (dummies) >> x - + Size: 32B array([[25, 35], [10, 24]]) Coordinates: - * lat (lat) float64 35.0 40.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 16B 35.0 40.0 + * lon (lon) float64 16B 100.0 120.0 >>> y - + Size: 32B array([[20, 5], [ 7, 13]]) Coordinates: - * lat (lat) float64 35.0 42.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 16B 35.0 42.0 + * lon (lon) float64 16B 100.0 120.0 >>> a, b = xr.align(x, y) >>> a - + Size: 16B array([[25, 35]]) Coordinates: - * lat (lat) float64 35.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 8B 35.0 + * lon (lon) float64 16B 100.0 120.0 >>> b - + Size: 16B array([[20, 5]]) Coordinates: - * lat (lat) float64 35.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 8B 35.0 + * lon (lon) float64 16B 100.0 120.0 >>> a, b = xr.align(x, y, join="outer") >>> a - + Size: 48B array([[25., 35.], [10., 24.], [nan, nan]]) Coordinates: - * lat (lat) float64 35.0 40.0 42.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 24B 35.0 40.0 42.0 + * lon (lon) float64 16B 100.0 120.0 >>> b - + Size: 48B array([[20., 5.], [nan, nan], [ 7., 13.]]) Coordinates: - * lat (lat) float64 35.0 40.0 42.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 24B 35.0 40.0 42.0 + * lon (lon) float64 16B 100.0 120.0 >>> a, b = xr.align(x, y, join="outer", fill_value=-999) >>> a - + Size: 48B array([[ 25, 35], [ 10, 24], [-999, -999]]) Coordinates: - * lat (lat) float64 35.0 40.0 42.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 24B 35.0 40.0 42.0 + * lon (lon) float64 16B 100.0 120.0 >>> b - + Size: 48B array([[ 20, 5], [-999, -999], [ 7, 13]]) Coordinates: - * lat (lat) float64 35.0 40.0 42.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 24B 35.0 40.0 42.0 + * lon (lon) float64 16B 100.0 120.0 >>> a, b = xr.align(x, y, join="left") >>> a - + Size: 32B array([[25, 35], [10, 24]]) Coordinates: - * lat (lat) float64 35.0 40.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 16B 35.0 40.0 + * lon (lon) float64 16B 100.0 120.0 >>> b - + Size: 32B array([[20., 5.], [nan, nan]]) Coordinates: - * lat (lat) float64 35.0 40.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 16B 35.0 40.0 + * lon (lon) float64 16B 100.0 120.0 >>> a, b = xr.align(x, y, join="right") >>> a - + Size: 32B array([[25., 35.], [nan, nan]]) Coordinates: - * lat (lat) float64 35.0 42.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 16B 35.0 42.0 + * lon (lon) float64 16B 100.0 120.0 >>> b - + Size: 32B array([[20, 5], [ 7, 13]]) Coordinates: - * lat (lat) float64 35.0 42.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 16B 35.0 42.0 + * lon (lon) float64 16B 100.0 120.0 >>> a, b = xr.align(x, y, join="exact") Traceback (most recent call last): @@ -862,19 +862,19 @@ def align( >>> a, b = xr.align(x, y, join="override") >>> a - + Size: 32B array([[25, 35], [10, 24]]) Coordinates: - * lat (lat) float64 35.0 40.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 16B 35.0 40.0 + * lon (lon) float64 16B 100.0 120.0 >>> b - + Size: 32B array([[20, 5], [ 7, 13]]) Coordinates: - * lat (lat) float64 35.0 40.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 16B 35.0 40.0 + * lon (lon) float64 16B 100.0 120.0 """ aligner = Aligner( @@ -1185,22 +1185,22 @@ def broadcast( >>> a = xr.DataArray([1, 2, 3], dims="x") >>> b = xr.DataArray([5, 6], dims="y") >>> a - + Size: 24B array([1, 2, 3]) Dimensions without coordinates: x >>> b - + Size: 16B array([5, 6]) Dimensions without coordinates: y >>> a2, b2 = xr.broadcast(a, b) >>> a2 - + Size: 48B array([[1, 1], [2, 2], [3, 3]]) Dimensions without coordinates: x, y >>> b2 - + Size: 48B array([[5, 6], [5, 6], [5, 6]]) @@ -1211,12 +1211,12 @@ def broadcast( >>> ds = xr.Dataset({"a": a, "b": b}) >>> (ds2,) = xr.broadcast(ds) # use tuple unpacking to extract one dataset >>> ds2 - + Size: 96B Dimensions: (x: 3, y: 2) Dimensions without coordinates: x, y Data variables: - a (x, y) int64 1 1 2 2 3 3 - b (x, y) int64 5 6 5 6 5 6 + a (x, y) int64 48B 1 1 2 2 3 3 + b (x, y) int64 48B 5 6 5 6 5 6 """ if exclude is None: diff --git a/xarray/core/combine.py b/xarray/core/combine.py index 6e794bd898b..f3c73e9b319 100644 --- a/xarray/core/combine.py +++ b/xarray/core/combine.py @@ -484,12 +484,12 @@ def combine_nested( ... } ... ) >>> x1y1 - + Size: 64B Dimensions: (x: 2, y: 2) Dimensions without coordinates: x, y Data variables: - temperature (x, y) float64 1.764 0.4002 0.9787 2.241 - precipitation (x, y) float64 1.868 -0.9773 0.9501 -0.1514 + temperature (x, y) float64 32B 1.764 0.4002 0.9787 2.241 + precipitation (x, y) float64 32B 1.868 -0.9773 0.9501 -0.1514 >>> x1y2 = xr.Dataset( ... { ... "temperature": (("x", "y"), np.random.randn(2, 2)), @@ -513,12 +513,12 @@ def combine_nested( >>> ds_grid = [[x1y1, x1y2], [x2y1, x2y2]] >>> combined = xr.combine_nested(ds_grid, concat_dim=["x", "y"]) >>> combined - + Size: 256B Dimensions: (x: 4, y: 4) Dimensions without coordinates: x, y Data variables: - temperature (x, y) float64 1.764 0.4002 -0.1032 ... 0.04576 -0.1872 - precipitation (x, y) float64 1.868 -0.9773 0.761 ... -0.7422 0.1549 0.3782 + temperature (x, y) float64 128B 1.764 0.4002 -0.1032 ... 0.04576 -0.1872 + precipitation (x, y) float64 128B 1.868 -0.9773 0.761 ... 0.1549 0.3782 ``combine_nested`` can also be used to explicitly merge datasets with different variables. For example if we have 4 datasets, which are divided @@ -528,19 +528,19 @@ def combine_nested( >>> t1temp = xr.Dataset({"temperature": ("t", np.random.randn(5))}) >>> t1temp - + Size: 40B Dimensions: (t: 5) Dimensions without coordinates: t Data variables: - temperature (t) float64 -0.8878 -1.981 -0.3479 0.1563 1.23 + temperature (t) float64 40B -0.8878 -1.981 -0.3479 0.1563 1.23 >>> t1precip = xr.Dataset({"precipitation": ("t", np.random.randn(5))}) >>> t1precip - + Size: 40B Dimensions: (t: 5) Dimensions without coordinates: t Data variables: - precipitation (t) float64 1.202 -0.3873 -0.3023 -1.049 -1.42 + precipitation (t) float64 40B 1.202 -0.3873 -0.3023 -1.049 -1.42 >>> t2temp = xr.Dataset({"temperature": ("t", np.random.randn(5))}) >>> t2precip = xr.Dataset({"precipitation": ("t", np.random.randn(5))}) @@ -549,12 +549,12 @@ def combine_nested( >>> ds_grid = [[t1temp, t1precip], [t2temp, t2precip]] >>> combined = xr.combine_nested(ds_grid, concat_dim=["t", None]) >>> combined - + Size: 160B Dimensions: (t: 10) Dimensions without coordinates: t Data variables: - temperature (t) float64 -0.8878 -1.981 -0.3479 ... -0.5097 -0.4381 -1.253 - precipitation (t) float64 1.202 -0.3873 -0.3023 ... -0.2127 -0.8955 0.3869 + temperature (t) float64 80B -0.8878 -1.981 -0.3479 ... -0.4381 -1.253 + precipitation (t) float64 80B 1.202 -0.3873 -0.3023 ... -0.8955 0.3869 See also -------- @@ -797,74 +797,74 @@ def combine_by_coords( ... ) >>> x1 - + Size: 136B Dimensions: (y: 2, x: 3) Coordinates: - * y (y) int64 0 1 - * x (x) int64 10 20 30 + * y (y) int64 16B 0 1 + * x (x) int64 24B 10 20 30 Data variables: - temperature (y, x) float64 10.98 14.3 12.06 10.9 8.473 12.92 - precipitation (y, x) float64 0.4376 0.8918 0.9637 0.3834 0.7917 0.5289 + temperature (y, x) float64 48B 10.98 14.3 12.06 10.9 8.473 12.92 + precipitation (y, x) float64 48B 0.4376 0.8918 0.9637 0.3834 0.7917 0.5289 >>> x2 - + Size: 136B Dimensions: (y: 2, x: 3) Coordinates: - * y (y) int64 2 3 - * x (x) int64 10 20 30 + * y (y) int64 16B 2 3 + * x (x) int64 24B 10 20 30 Data variables: - temperature (y, x) float64 11.36 18.51 1.421 1.743 0.4044 16.65 - precipitation (y, x) float64 0.7782 0.87 0.9786 0.7992 0.4615 0.7805 + temperature (y, x) float64 48B 11.36 18.51 1.421 1.743 0.4044 16.65 + precipitation (y, x) float64 48B 0.7782 0.87 0.9786 0.7992 0.4615 0.7805 >>> x3 - + Size: 136B Dimensions: (y: 2, x: 3) Coordinates: - * y (y) int64 2 3 - * x (x) int64 40 50 60 + * y (y) int64 16B 2 3 + * x (x) int64 24B 40 50 60 Data variables: - temperature (y, x) float64 2.365 12.8 2.867 18.89 10.44 8.293 - precipitation (y, x) float64 0.2646 0.7742 0.4562 0.5684 0.01879 0.6176 + temperature (y, x) float64 48B 2.365 12.8 2.867 18.89 10.44 8.293 + precipitation (y, x) float64 48B 0.2646 0.7742 0.4562 0.5684 0.01879 0.6176 >>> xr.combine_by_coords([x2, x1]) - + Size: 248B Dimensions: (y: 4, x: 3) Coordinates: - * y (y) int64 0 1 2 3 - * x (x) int64 10 20 30 + * y (y) int64 32B 0 1 2 3 + * x (x) int64 24B 10 20 30 Data variables: - temperature (y, x) float64 10.98 14.3 12.06 10.9 ... 1.743 0.4044 16.65 - precipitation (y, x) float64 0.4376 0.8918 0.9637 ... 0.7992 0.4615 0.7805 + temperature (y, x) float64 96B 10.98 14.3 12.06 ... 1.743 0.4044 16.65 + precipitation (y, x) float64 96B 0.4376 0.8918 0.9637 ... 0.4615 0.7805 >>> xr.combine_by_coords([x3, x1]) - + Size: 464B Dimensions: (y: 4, x: 6) Coordinates: - * y (y) int64 0 1 2 3 - * x (x) int64 10 20 30 40 50 60 + * y (y) int64 32B 0 1 2 3 + * x (x) int64 48B 10 20 30 40 50 60 Data variables: - temperature (y, x) float64 10.98 14.3 12.06 nan ... nan 18.89 10.44 8.293 - precipitation (y, x) float64 0.4376 0.8918 0.9637 ... 0.5684 0.01879 0.6176 + temperature (y, x) float64 192B 10.98 14.3 12.06 ... 18.89 10.44 8.293 + precipitation (y, x) float64 192B 0.4376 0.8918 0.9637 ... 0.01879 0.6176 >>> xr.combine_by_coords([x3, x1], join="override") - + Size: 256B Dimensions: (y: 2, x: 6) Coordinates: - * y (y) int64 0 1 - * x (x) int64 10 20 30 40 50 60 + * y (y) int64 16B 0 1 + * x (x) int64 48B 10 20 30 40 50 60 Data variables: - temperature (y, x) float64 10.98 14.3 12.06 2.365 ... 18.89 10.44 8.293 - precipitation (y, x) float64 0.4376 0.8918 0.9637 ... 0.5684 0.01879 0.6176 + temperature (y, x) float64 96B 10.98 14.3 12.06 ... 18.89 10.44 8.293 + precipitation (y, x) float64 96B 0.4376 0.8918 0.9637 ... 0.01879 0.6176 >>> xr.combine_by_coords([x1, x2, x3]) - + Size: 464B Dimensions: (y: 4, x: 6) Coordinates: - * y (y) int64 0 1 2 3 - * x (x) int64 10 20 30 40 50 60 + * y (y) int64 32B 0 1 2 3 + * x (x) int64 48B 10 20 30 40 50 60 Data variables: - temperature (y, x) float64 10.98 14.3 12.06 nan ... 18.89 10.44 8.293 - precipitation (y, x) float64 0.4376 0.8918 0.9637 ... 0.5684 0.01879 0.6176 + temperature (y, x) float64 192B 10.98 14.3 12.06 ... 18.89 10.44 8.293 + precipitation (y, x) float64 192B 0.4376 0.8918 0.9637 ... 0.01879 0.6176 You can also combine DataArray objects, but the behaviour will differ depending on whether or not the DataArrays are named. If all DataArrays are named then they will @@ -875,37 +875,37 @@ def combine_by_coords( ... name="a", data=[1.0, 2.0], coords={"x": [0, 1]}, dims="x" ... ) >>> named_da1 - + Size: 16B array([1., 2.]) Coordinates: - * x (x) int64 0 1 + * x (x) int64 16B 0 1 >>> named_da2 = xr.DataArray( ... name="a", data=[3.0, 4.0], coords={"x": [2, 3]}, dims="x" ... ) >>> named_da2 - + Size: 16B array([3., 4.]) Coordinates: - * x (x) int64 2 3 + * x (x) int64 16B 2 3 >>> xr.combine_by_coords([named_da1, named_da2]) - + Size: 64B Dimensions: (x: 4) Coordinates: - * x (x) int64 0 1 2 3 + * x (x) int64 32B 0 1 2 3 Data variables: - a (x) float64 1.0 2.0 3.0 4.0 + a (x) float64 32B 1.0 2.0 3.0 4.0 If all the DataArrays are unnamed, a single DataArray will be returned, e.g. >>> unnamed_da1 = xr.DataArray(data=[1.0, 2.0], coords={"x": [0, 1]}, dims="x") >>> unnamed_da2 = xr.DataArray(data=[3.0, 4.0], coords={"x": [2, 3]}, dims="x") >>> xr.combine_by_coords([unnamed_da1, unnamed_da2]) - + Size: 32B array([1., 2., 3., 4.]) Coordinates: - * x (x) int64 0 1 2 3 + * x (x) int64 32B 0 1 2 3 Finally, if you attempt to combine a mix of unnamed DataArrays with either named DataArrays or Datasets, a ValueError will be raised (as this is an ambiguous operation). diff --git a/xarray/core/common.py b/xarray/core/common.py index 9f3c8eabf7b..4635bc2c8c1 100644 --- a/xarray/core/common.py +++ b/xarray/core/common.py @@ -529,33 +529,33 @@ def assign_coords( ... dims="lon", ... ) >>> da - + Size: 32B array([0.5488135 , 0.71518937, 0.60276338, 0.54488318]) Coordinates: - * lon (lon) int64 358 359 0 1 + * lon (lon) int64 32B 358 359 0 1 >>> da.assign_coords(lon=(((da.lon + 180) % 360) - 180)) - + Size: 32B array([0.5488135 , 0.71518937, 0.60276338, 0.54488318]) Coordinates: - * lon (lon) int64 -2 -1 0 1 + * lon (lon) int64 32B -2 -1 0 1 The function also accepts dictionary arguments: >>> da.assign_coords({"lon": (((da.lon + 180) % 360) - 180)}) - + Size: 32B array([0.5488135 , 0.71518937, 0.60276338, 0.54488318]) Coordinates: - * lon (lon) int64 -2 -1 0 1 + * lon (lon) int64 32B -2 -1 0 1 New coordinate can also be attached to an existing dimension: >>> lon_2 = np.array([300, 289, 0, 1]) >>> da.assign_coords(lon_2=("lon", lon_2)) - + Size: 32B array([0.5488135 , 0.71518937, 0.60276338, 0.54488318]) Coordinates: - * lon (lon) int64 358 359 0 1 - lon_2 (lon) int64 300 289 0 1 + * lon (lon) int64 32B 358 359 0 1 + lon_2 (lon) int64 32B 300 289 0 1 Note that the same result can also be obtained with a dict e.g. @@ -581,31 +581,31 @@ def assign_coords( ... attrs=dict(description="Weather-related data"), ... ) >>> ds - + Size: 360B Dimensions: (x: 2, y: 2, time: 4) Coordinates: - lon (x, y) float64 260.2 260.7 260.2 260.8 - lat (x, y) float64 42.25 42.21 42.63 42.59 - * time (time) datetime64[ns] 2014-09-06 2014-09-07 ... 2014-09-09 - reference_time datetime64[ns] 2014-09-05 + lon (x, y) float64 32B 260.2 260.7 260.2 260.8 + lat (x, y) float64 32B 42.25 42.21 42.63 42.59 + * time (time) datetime64[ns] 32B 2014-09-06 ... 2014-09-09 + reference_time datetime64[ns] 8B 2014-09-05 Dimensions without coordinates: x, y Data variables: - temperature (x, y, time) float64 20.0 20.8 21.6 22.4 ... 30.4 31.2 32.0 - precipitation (x, y, time) float64 2.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 2.0 + temperature (x, y, time) float64 128B 20.0 20.8 21.6 ... 30.4 31.2 32.0 + precipitation (x, y, time) float64 128B 2.0 0.0 0.0 0.0 ... 0.0 0.0 2.0 Attributes: description: Weather-related data >>> ds.assign_coords(lon=(((ds.lon + 180) % 360) - 180)) - + Size: 360B Dimensions: (x: 2, y: 2, time: 4) Coordinates: - lon (x, y) float64 -99.83 -99.32 -99.79 -99.23 - lat (x, y) float64 42.25 42.21 42.63 42.59 - * time (time) datetime64[ns] 2014-09-06 2014-09-07 ... 2014-09-09 - reference_time datetime64[ns] 2014-09-05 + lon (x, y) float64 32B -99.83 -99.32 -99.79 -99.23 + lat (x, y) float64 32B 42.25 42.21 42.63 42.59 + * time (time) datetime64[ns] 32B 2014-09-06 ... 2014-09-09 + reference_time datetime64[ns] 8B 2014-09-05 Dimensions without coordinates: x, y Data variables: - temperature (x, y, time) float64 20.0 20.8 21.6 22.4 ... 30.4 31.2 32.0 - precipitation (x, y, time) float64 2.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 2.0 + temperature (x, y, time) float64 128B 20.0 20.8 21.6 ... 30.4 31.2 32.0 + precipitation (x, y, time) float64 128B 2.0 0.0 0.0 0.0 ... 0.0 0.0 2.0 Attributes: description: Weather-related data @@ -645,10 +645,10 @@ def assign_attrs(self, *args: Any, **kwargs: Any) -> Self: -------- >>> dataset = xr.Dataset({"temperature": [25, 30, 27]}) >>> dataset - + Size: 24B Dimensions: (temperature: 3) Coordinates: - * temperature (temperature) int64 25 30 27 + * temperature (temperature) int64 24B 25 30 27 Data variables: *empty* @@ -656,10 +656,10 @@ def assign_attrs(self, *args: Any, **kwargs: Any) -> Self: ... units="Celsius", description="Temperature data" ... ) >>> new_dataset - + Size: 24B Dimensions: (temperature: 3) Coordinates: - * temperature (temperature) int64 25 30 27 + * temperature (temperature) int64 24B 25 30 27 Data variables: *empty* Attributes: @@ -749,14 +749,14 @@ def pipe( ... coords={"lat": [10, 20], "lon": [150, 160]}, ... ) >>> x - + Size: 96B Dimensions: (lat: 2, lon: 2) Coordinates: - * lat (lat) int64 10 20 - * lon (lon) int64 150 160 + * lat (lat) int64 16B 10 20 + * lon (lon) int64 16B 150 160 Data variables: - temperature_c (lat, lon) float64 10.98 14.3 12.06 10.9 - precipitation (lat, lon) float64 0.4237 0.6459 0.4376 0.8918 + temperature_c (lat, lon) float64 32B 10.98 14.3 12.06 10.9 + precipitation (lat, lon) float64 32B 0.4237 0.6459 0.4376 0.8918 >>> def adder(data, arg): ... return data + arg @@ -768,38 +768,38 @@ def pipe( ... return (data * mult_arg) - sub_arg ... >>> x.pipe(adder, 2) - + Size: 96B Dimensions: (lat: 2, lon: 2) Coordinates: - * lat (lat) int64 10 20 - * lon (lon) int64 150 160 + * lat (lat) int64 16B 10 20 + * lon (lon) int64 16B 150 160 Data variables: - temperature_c (lat, lon) float64 12.98 16.3 14.06 12.9 - precipitation (lat, lon) float64 2.424 2.646 2.438 2.892 + temperature_c (lat, lon) float64 32B 12.98 16.3 14.06 12.9 + precipitation (lat, lon) float64 32B 2.424 2.646 2.438 2.892 >>> x.pipe(adder, arg=2) - + Size: 96B Dimensions: (lat: 2, lon: 2) Coordinates: - * lat (lat) int64 10 20 - * lon (lon) int64 150 160 + * lat (lat) int64 16B 10 20 + * lon (lon) int64 16B 150 160 Data variables: - temperature_c (lat, lon) float64 12.98 16.3 14.06 12.9 - precipitation (lat, lon) float64 2.424 2.646 2.438 2.892 + temperature_c (lat, lon) float64 32B 12.98 16.3 14.06 12.9 + precipitation (lat, lon) float64 32B 2.424 2.646 2.438 2.892 >>> ( ... x.pipe(adder, arg=2) ... .pipe(div, arg=2) ... .pipe(sub_mult, sub_arg=2, mult_arg=2) ... ) - + Size: 96B Dimensions: (lat: 2, lon: 2) Coordinates: - * lat (lat) int64 10 20 - * lon (lon) int64 150 160 + * lat (lat) int64 16B 10 20 + * lon (lon) int64 16B 150 160 Data variables: - temperature_c (lat, lon) float64 10.98 14.3 12.06 10.9 - precipitation (lat, lon) float64 0.4237 0.6459 0.4376 0.8918 + temperature_c (lat, lon) float64 32B 10.98 14.3 12.06 10.9 + precipitation (lat, lon) float64 32B 0.4237 0.6459 0.4376 0.8918 See Also -------- @@ -949,36 +949,96 @@ def _resample( ... dims="time", ... ) >>> da - + Size: 96B array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.]) Coordinates: - * time (time) datetime64[ns] 1999-12-15 2000-01-15 ... 2000-11-15 + * time (time) datetime64[ns] 96B 1999-12-15 2000-01-15 ... 2000-11-15 >>> da.resample(time="QS-DEC").mean() - + Size: 32B array([ 1., 4., 7., 10.]) Coordinates: - * time (time) datetime64[ns] 1999-12-01 2000-03-01 2000-06-01 2000-09-01 + * time (time) datetime64[ns] 32B 1999-12-01 2000-03-01 ... 2000-09-01 Upsample monthly time-series data to daily data: >>> da.resample(time="1D").interpolate("linear") # +doctest: ELLIPSIS - + Size: 3kB array([ 0. , 0.03225806, 0.06451613, 0.09677419, 0.12903226, 0.16129032, 0.19354839, 0.22580645, 0.25806452, 0.29032258, 0.32258065, 0.35483871, 0.38709677, 0.41935484, 0.4516129 , + 0.48387097, 0.51612903, 0.5483871 , 0.58064516, 0.61290323, + 0.64516129, 0.67741935, 0.70967742, 0.74193548, 0.77419355, + 0.80645161, 0.83870968, 0.87096774, 0.90322581, 0.93548387, + 0.96774194, 1. , 1.03225806, 1.06451613, 1.09677419, + 1.12903226, 1.16129032, 1.19354839, 1.22580645, 1.25806452, + 1.29032258, 1.32258065, 1.35483871, 1.38709677, 1.41935484, + 1.4516129 , 1.48387097, 1.51612903, 1.5483871 , 1.58064516, + 1.61290323, 1.64516129, 1.67741935, 1.70967742, 1.74193548, + 1.77419355, 1.80645161, 1.83870968, 1.87096774, 1.90322581, + 1.93548387, 1.96774194, 2. , 2.03448276, 2.06896552, + 2.10344828, 2.13793103, 2.17241379, 2.20689655, 2.24137931, + 2.27586207, 2.31034483, 2.34482759, 2.37931034, 2.4137931 , + 2.44827586, 2.48275862, 2.51724138, 2.55172414, 2.5862069 , + 2.62068966, 2.65517241, 2.68965517, 2.72413793, 2.75862069, + 2.79310345, 2.82758621, 2.86206897, 2.89655172, 2.93103448, + 2.96551724, 3. , 3.03225806, 3.06451613, 3.09677419, + 3.12903226, 3.16129032, 3.19354839, 3.22580645, 3.25806452, ... + 7.87096774, 7.90322581, 7.93548387, 7.96774194, 8. , + 8.03225806, 8.06451613, 8.09677419, 8.12903226, 8.16129032, + 8.19354839, 8.22580645, 8.25806452, 8.29032258, 8.32258065, + 8.35483871, 8.38709677, 8.41935484, 8.4516129 , 8.48387097, + 8.51612903, 8.5483871 , 8.58064516, 8.61290323, 8.64516129, + 8.67741935, 8.70967742, 8.74193548, 8.77419355, 8.80645161, + 8.83870968, 8.87096774, 8.90322581, 8.93548387, 8.96774194, + 9. , 9.03333333, 9.06666667, 9.1 , 9.13333333, + 9.16666667, 9.2 , 9.23333333, 9.26666667, 9.3 , + 9.33333333, 9.36666667, 9.4 , 9.43333333, 9.46666667, + 9.5 , 9.53333333, 9.56666667, 9.6 , 9.63333333, + 9.66666667, 9.7 , 9.73333333, 9.76666667, 9.8 , + 9.83333333, 9.86666667, 9.9 , 9.93333333, 9.96666667, + 10. , 10.03225806, 10.06451613, 10.09677419, 10.12903226, + 10.16129032, 10.19354839, 10.22580645, 10.25806452, 10.29032258, + 10.32258065, 10.35483871, 10.38709677, 10.41935484, 10.4516129 , + 10.48387097, 10.51612903, 10.5483871 , 10.58064516, 10.61290323, + 10.64516129, 10.67741935, 10.70967742, 10.74193548, 10.77419355, 10.80645161, 10.83870968, 10.87096774, 10.90322581, 10.93548387, 10.96774194, 11. ]) Coordinates: - * time (time) datetime64[ns] 1999-12-15 1999-12-16 ... 2000-11-15 + * time (time) datetime64[ns] 3kB 1999-12-15 1999-12-16 ... 2000-11-15 Limit scope of upsampling method >>> da.resample(time="1D").nearest(tolerance="1D") - - array([ 0., 0., nan, ..., nan, 11., 11.]) + Size: 3kB + array([ 0., 0., nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, 1., 1., 1., nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, 2., 2., 2., nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 3., + 3., 3., nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, 4., 4., 4., nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, 5., 5., 5., nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + 6., 6., 6., nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, 7., 7., 7., nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, 8., 8., 8., nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, 9., 9., 9., nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, 10., 10., 10., nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 11., 11.]) Coordinates: - * time (time) datetime64[ns] 1999-12-15 1999-12-16 ... 2000-11-15 + * time (time) datetime64[ns] 3kB 1999-12-15 1999-12-16 ... 2000-11-15 See Also -------- @@ -1095,7 +1155,7 @@ def where(self, cond: Any, other: Any = dtypes.NA, drop: bool = False) -> Self: -------- >>> a = xr.DataArray(np.arange(25).reshape(5, 5), dims=("x", "y")) >>> a - + Size: 200B array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], @@ -1104,7 +1164,7 @@ def where(self, cond: Any, other: Any = dtypes.NA, drop: bool = False) -> Self: Dimensions without coordinates: x, y >>> a.where(a.x + a.y < 4) - + Size: 200B array([[ 0., 1., 2., 3., nan], [ 5., 6., 7., nan, nan], [10., 11., nan, nan, nan], @@ -1113,7 +1173,7 @@ def where(self, cond: Any, other: Any = dtypes.NA, drop: bool = False) -> Self: Dimensions without coordinates: x, y >>> a.where(a.x + a.y < 5, -1) - + Size: 200B array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, -1], [10, 11, 12, -1, -1], @@ -1122,7 +1182,7 @@ def where(self, cond: Any, other: Any = dtypes.NA, drop: bool = False) -> Self: Dimensions without coordinates: x, y >>> a.where(a.x + a.y < 4, drop=True) - + Size: 128B array([[ 0., 1., 2., 3.], [ 5., 6., 7., nan], [10., 11., nan, nan], @@ -1130,7 +1190,7 @@ def where(self, cond: Any, other: Any = dtypes.NA, drop: bool = False) -> Self: Dimensions without coordinates: x, y >>> a.where(lambda x: x.x + x.y < 4, lambda x: -x) - + Size: 200B array([[ 0, 1, 2, 3, -4], [ 5, 6, 7, -8, -9], [ 10, 11, -12, -13, -14], @@ -1139,7 +1199,7 @@ def where(self, cond: Any, other: Any = dtypes.NA, drop: bool = False) -> Self: Dimensions without coordinates: x, y >>> a.where(a.x + a.y < 4, drop=True) - + Size: 128B array([[ 0., 1., 2., 3.], [ 5., 6., 7., nan], [10., 11., nan, nan], @@ -1236,11 +1296,11 @@ def isnull(self, keep_attrs: bool | None = None) -> Self: -------- >>> array = xr.DataArray([1, np.nan, 3], dims="x") >>> array - + Size: 24B array([ 1., nan, 3.]) Dimensions without coordinates: x >>> array.isnull() - + Size: 3B array([False, True, False]) Dimensions without coordinates: x """ @@ -1279,11 +1339,11 @@ def notnull(self, keep_attrs: bool | None = None) -> Self: -------- >>> array = xr.DataArray([1, np.nan, 3], dims="x") >>> array - + Size: 24B array([ 1., nan, 3.]) Dimensions without coordinates: x >>> array.notnull() - + Size: 3B array([ True, False, True]) Dimensions without coordinates: x """ @@ -1318,7 +1378,7 @@ def isin(self, test_elements: Any) -> Self: -------- >>> array = xr.DataArray([1, 2, 3], dims="x") >>> array.isin([1, 3]) - + Size: 3B array([ True, False, True]) Dimensions without coordinates: x @@ -1553,72 +1613,72 @@ def full_like( ... coords={"lat": [1, 2], "lon": [0, 1, 2]}, ... ) >>> x - + Size: 48B array([[0, 1, 2], [3, 4, 5]]) Coordinates: - * lat (lat) int64 1 2 - * lon (lon) int64 0 1 2 + * lat (lat) int64 16B 1 2 + * lon (lon) int64 24B 0 1 2 >>> xr.full_like(x, 1) - + Size: 48B array([[1, 1, 1], [1, 1, 1]]) Coordinates: - * lat (lat) int64 1 2 - * lon (lon) int64 0 1 2 + * lat (lat) int64 16B 1 2 + * lon (lon) int64 24B 0 1 2 >>> xr.full_like(x, 0.5) - + Size: 48B array([[0, 0, 0], [0, 0, 0]]) Coordinates: - * lat (lat) int64 1 2 - * lon (lon) int64 0 1 2 + * lat (lat) int64 16B 1 2 + * lon (lon) int64 24B 0 1 2 >>> xr.full_like(x, 0.5, dtype=np.double) - + Size: 48B array([[0.5, 0.5, 0.5], [0.5, 0.5, 0.5]]) Coordinates: - * lat (lat) int64 1 2 - * lon (lon) int64 0 1 2 + * lat (lat) int64 16B 1 2 + * lon (lon) int64 24B 0 1 2 >>> xr.full_like(x, np.nan, dtype=np.double) - + Size: 48B array([[nan, nan, nan], [nan, nan, nan]]) Coordinates: - * lat (lat) int64 1 2 - * lon (lon) int64 0 1 2 + * lat (lat) int64 16B 1 2 + * lon (lon) int64 24B 0 1 2 >>> ds = xr.Dataset( ... {"a": ("x", [3, 5, 2]), "b": ("x", [9, 1, 0])}, coords={"x": [2, 4, 6]} ... ) >>> ds - + Size: 72B Dimensions: (x: 3) Coordinates: - * x (x) int64 2 4 6 + * x (x) int64 24B 2 4 6 Data variables: - a (x) int64 3 5 2 - b (x) int64 9 1 0 + a (x) int64 24B 3 5 2 + b (x) int64 24B 9 1 0 >>> xr.full_like(ds, fill_value={"a": 1, "b": 2}) - + Size: 72B Dimensions: (x: 3) Coordinates: - * x (x) int64 2 4 6 + * x (x) int64 24B 2 4 6 Data variables: - a (x) int64 1 1 1 - b (x) int64 2 2 2 + a (x) int64 24B 1 1 1 + b (x) int64 24B 2 2 2 >>> xr.full_like(ds, fill_value={"a": 1, "b": 2}, dtype={"a": bool, "b": float}) - + Size: 51B Dimensions: (x: 3) Coordinates: - * x (x) int64 2 4 6 + * x (x) int64 24B 2 4 6 Data variables: - a (x) bool True True True - b (x) float64 2.0 2.0 2.0 + a (x) bool 3B True True True + b (x) float64 24B 2.0 2.0 2.0 See Also -------- @@ -1832,28 +1892,28 @@ def zeros_like( ... coords={"lat": [1, 2], "lon": [0, 1, 2]}, ... ) >>> x - + Size: 48B array([[0, 1, 2], [3, 4, 5]]) Coordinates: - * lat (lat) int64 1 2 - * lon (lon) int64 0 1 2 + * lat (lat) int64 16B 1 2 + * lon (lon) int64 24B 0 1 2 >>> xr.zeros_like(x) - + Size: 48B array([[0, 0, 0], [0, 0, 0]]) Coordinates: - * lat (lat) int64 1 2 - * lon (lon) int64 0 1 2 + * lat (lat) int64 16B 1 2 + * lon (lon) int64 24B 0 1 2 >>> xr.zeros_like(x, dtype=float) - + Size: 48B array([[0., 0., 0.], [0., 0., 0.]]) Coordinates: - * lat (lat) int64 1 2 - * lon (lon) int64 0 1 2 + * lat (lat) int64 16B 1 2 + * lon (lon) int64 24B 0 1 2 See Also -------- @@ -1974,20 +2034,20 @@ def ones_like( ... coords={"lat": [1, 2], "lon": [0, 1, 2]}, ... ) >>> x - + Size: 48B array([[0, 1, 2], [3, 4, 5]]) Coordinates: - * lat (lat) int64 1 2 - * lon (lon) int64 0 1 2 + * lat (lat) int64 16B 1 2 + * lon (lon) int64 24B 0 1 2 >>> xr.ones_like(x) - + Size: 48B array([[1, 1, 1], [1, 1, 1]]) Coordinates: - * lat (lat) int64 1 2 - * lon (lon) int64 0 1 2 + * lat (lat) int64 16B 1 2 + * lon (lon) int64 24B 0 1 2 See Also -------- diff --git a/xarray/core/computation.py b/xarray/core/computation.py index 3d88555e65a..89d757bf30a 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1059,10 +1059,10 @@ def apply_ufunc( >>> array = xr.DataArray([1, 2, 3], coords=[("x", [0.1, 0.2, 0.3])]) >>> magnitude(array, -array) - + Size: 24B array([1.41421356, 2.82842712, 4.24264069]) Coordinates: - * x (x) float64 0.1 0.2 0.3 + * x (x) float64 24B 0.1 0.2 0.3 Plain scalars, numpy arrays and a mix of these with xarray objects is also supported: @@ -1072,10 +1072,10 @@ def apply_ufunc( >>> magnitude(3, np.array([0, 4])) array([3., 5.]) >>> magnitude(array, 0) - + Size: 24B array([1., 2., 3.]) Coordinates: - * x (x) float64 0.1 0.2 0.3 + * x (x) float64 24B 0.1 0.2 0.3 Other examples of how you could use ``apply_ufunc`` to write functions to (very nearly) replicate existing xarray functionality: @@ -1328,13 +1328,13 @@ def cov( ... ], ... ) >>> da_a - + Size: 72B array([[1. , 2. , 3. ], [0.1, 0.2, 0.3], [3.2, 0.6, 1.8]]) Coordinates: - * space (space) >> da_b = DataArray( ... np.array([[0.2, 0.4, 0.6], [15, 10, 5], [3.2, 0.6, 1.8]]), ... dims=("space", "time"), @@ -1344,21 +1344,21 @@ def cov( ... ], ... ) >>> da_b - + Size: 72B array([[ 0.2, 0.4, 0.6], [15. , 10. , 5. ], [ 3.2, 0.6, 1.8]]) Coordinates: - * space (space) >> xr.cov(da_a, da_b) - + Size: 8B array(-3.53055556) >>> xr.cov(da_a, da_b, dim="time") - + Size: 24B array([ 0.2 , -0.5 , 1.69333333]) Coordinates: - * space (space) >> weights = DataArray( ... [4, 2, 1], ... dims=("space"), @@ -1367,15 +1367,15 @@ def cov( ... ], ... ) >>> weights - + Size: 24B array([4, 2, 1]) Coordinates: - * space (space) >> xr.cov(da_a, da_b, dim="space", weights=weights) - + Size: 24B array([-4.69346939, -4.49632653, -3.37959184]) Coordinates: - * time (time) datetime64[ns] 2000-01-01 2000-01-02 2000-01-03 + * time (time) datetime64[ns] 24B 2000-01-01 2000-01-02 2000-01-03 """ from xarray.core.dataarray import DataArray @@ -1432,13 +1432,13 @@ def corr( ... ], ... ) >>> da_a - + Size: 72B array([[1. , 2. , 3. ], [0.1, 0.2, 0.3], [3.2, 0.6, 1.8]]) Coordinates: - * space (space) >> da_b = DataArray( ... np.array([[0.2, 0.4, 0.6], [15, 10, 5], [3.2, 0.6, 1.8]]), ... dims=("space", "time"), @@ -1448,21 +1448,21 @@ def corr( ... ], ... ) >>> da_b - + Size: 72B array([[ 0.2, 0.4, 0.6], [15. , 10. , 5. ], [ 3.2, 0.6, 1.8]]) Coordinates: - * space (space) >> xr.corr(da_a, da_b) - + Size: 8B array(-0.57087777) >>> xr.corr(da_a, da_b, dim="time") - + Size: 24B array([ 1., -1., 1.]) Coordinates: - * space (space) >> weights = DataArray( ... [4, 2, 1], ... dims=("space"), @@ -1471,15 +1471,15 @@ def corr( ... ], ... ) >>> weights - + Size: 24B array([4, 2, 1]) Coordinates: - * space (space) >> xr.corr(da_a, da_b, dim="space", weights=weights) - + Size: 24B array([-0.50240504, -0.83215028, -0.99057446]) Coordinates: - * time (time) datetime64[ns] 2000-01-01 2000-01-02 2000-01-03 + * time (time) datetime64[ns] 24B 2000-01-01 2000-01-02 2000-01-03 """ from xarray.core.dataarray import DataArray @@ -1585,7 +1585,7 @@ def cross( >>> a = xr.DataArray([1, 2, 3]) >>> b = xr.DataArray([4, 5, 6]) >>> xr.cross(a, b, dim="dim_0") - + Size: 24B array([-3, 6, -3]) Dimensions without coordinates: dim_0 @@ -1595,7 +1595,7 @@ def cross( >>> 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 @@ -1604,7 +1604,7 @@ def cross( >>> a = xr.DataArray([1, 2, 0]) >>> b = xr.DataArray([4, 5, 0]) >>> xr.cross(a, b, dim="dim_0") - + Size: 24B array([ 0, 0, -3]) Dimensions without coordinates: dim_0 @@ -1621,10 +1621,10 @@ def cross( ... coords=dict(cartesian=(["cartesian"], ["x", "y", "z"])), ... ) >>> xr.cross(a, b, dim="cartesian") - + Size: 24B array([12, -6, -3]) Coordinates: - * cartesian (cartesian) >> xr.cross(a, b, dim="cartesian") - + Size: 24B array([-10, 2, 5]) Coordinates: - * cartesian (cartesian) >> xr.cross(a, b, dim="cartesian") - + Size: 48B array([[-3, 6, -3], [ 3, -6, 3]]) Coordinates: - * time (time) int64 0 1 - * cartesian (cartesian) >> c.to_dataset(dim="cartesian") - + Size: 24B Dimensions: (dim_0: 1) Dimensions without coordinates: dim_0 Data variables: - x (dim_0) int64 -3 - y (dim_0) int64 6 - z (dim_0) int64 -3 + x (dim_0) int64 8B -3 + y (dim_0) int64 8B 6 + z (dim_0) int64 8B -3 See Also -------- @@ -1807,14 +1807,14 @@ def dot( >>> da_c = xr.DataArray(np.arange(2 * 3).reshape(2, 3), dims=["c", "d"]) >>> da_a - + Size: 48B array([[0, 1], [2, 3], [4, 5]]) Dimensions without coordinates: a, b >>> da_b - + Size: 96B array([[[ 0, 1], [ 2, 3]], @@ -1826,36 +1826,36 @@ def dot( Dimensions without coordinates: a, b, c >>> da_c - + Size: 48B array([[0, 1, 2], [3, 4, 5]]) Dimensions without coordinates: c, d >>> xr.dot(da_a, da_b, dim=["a", "b"]) - + Size: 16B array([110, 125]) Dimensions without coordinates: c >>> xr.dot(da_a, da_b, dim=["a"]) - + Size: 32B array([[40, 46], [70, 79]]) Dimensions without coordinates: b, c >>> xr.dot(da_a, da_b, da_c, dim=["b", "c"]) - + Size: 72B array([[ 9, 14, 19], [ 93, 150, 207], [273, 446, 619]]) Dimensions without coordinates: a, d >>> xr.dot(da_a, da_b) - + Size: 16B array([110, 125]) Dimensions without coordinates: c >>> xr.dot(da_a, da_b, dim=...) - + Size: 8B array(235) """ from xarray.core.dataarray import DataArray @@ -1959,16 +1959,16 @@ def where(cond, x, y, keep_attrs=None): ... name="sst", ... ) >>> x - + Size: 80B array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]) Coordinates: - * lat (lat) int64 0 1 2 3 4 5 6 7 8 9 + * lat (lat) int64 80B 0 1 2 3 4 5 6 7 8 9 >>> xr.where(x < 0.5, x, x * 100) - + Size: 80B array([ 0. , 0.1, 0.2, 0.3, 0.4, 50. , 60. , 70. , 80. , 90. ]) Coordinates: - * lat (lat) int64 0 1 2 3 4 5 6 7 8 9 + * lat (lat) int64 80B 0 1 2 3 4 5 6 7 8 9 >>> y = xr.DataArray( ... 0.1 * np.arange(9).reshape(3, 3), @@ -1977,27 +1977,27 @@ def where(cond, x, y, keep_attrs=None): ... name="sst", ... ) >>> y - + Size: 72B array([[0. , 0.1, 0.2], [0.3, 0.4, 0.5], [0.6, 0.7, 0.8]]) Coordinates: - * lat (lat) int64 0 1 2 - * lon (lon) int64 10 11 12 + * lat (lat) int64 24B 0 1 2 + * lon (lon) int64 24B 10 11 12 >>> xr.where(y.lat < 1, y, -1) - + Size: 72B array([[ 0. , 0.1, 0.2], [-1. , -1. , -1. ], [-1. , -1. , -1. ]]) Coordinates: - * lat (lat) int64 0 1 2 - * lon (lon) int64 10 11 12 + * lat (lat) int64 24B 0 1 2 + * lon (lon) int64 24B 10 11 12 >>> cond = xr.DataArray([True, False], dims=["x"]) >>> x = xr.DataArray([1, 2], dims=["y"]) >>> xr.where(cond, x, 0) - + Size: 32B array([[1, 2], [0, 0]]) Dimensions without coordinates: x, y diff --git a/xarray/core/concat.py b/xarray/core/concat.py index 200a46053f6..86966966e39 100644 --- a/xarray/core/concat.py +++ b/xarray/core/concat.py @@ -179,46 +179,46 @@ def concat( ... np.arange(6).reshape(2, 3), [("x", ["a", "b"]), ("y", [10, 20, 30])] ... ) >>> da - + Size: 48B array([[0, 1, 2], [3, 4, 5]]) Coordinates: - * x (x) >> xr.concat([da.isel(y=slice(0, 1)), da.isel(y=slice(1, None))], dim="y") - + Size: 48B array([[0, 1, 2], [3, 4, 5]]) Coordinates: - * x (x) >> xr.concat([da.isel(x=0), da.isel(x=1)], "x") - + Size: 48B array([[0, 1, 2], [3, 4, 5]]) Coordinates: - * x (x) >> xr.concat([da.isel(x=0), da.isel(x=1)], "new_dim") - + Size: 48B array([[0, 1, 2], [3, 4, 5]]) Coordinates: - x (new_dim) >> xr.concat([da.isel(x=0), da.isel(x=1)], pd.Index([-90, -100], name="new_dim")) - + Size: 48B array([[0, 1, 2], [3, 4, 5]]) Coordinates: - x (new_dim) >> xr.Coordinates({"x": [1, 2]}) Coordinates: - * x (x) int64 1 2 + * x (x) int64 16B 1 2 Create a dimension coordinate with no index: >>> xr.Coordinates(coords={"x": [1, 2]}, indexes={}) Coordinates: - x (x) int64 1 2 + x (x) int64 16B 1 2 Create a new Coordinates object from existing dataset coordinates (indexes are passed): @@ -238,27 +238,27 @@ class Coordinates(AbstractCoordinates): >>> ds = xr.Dataset(coords={"x": [1, 2]}) >>> xr.Coordinates(ds.coords) Coordinates: - * x (x) int64 1 2 + * x (x) int64 16B 1 2 Create indexed coordinates from a ``pandas.MultiIndex`` object: >>> midx = pd.MultiIndex.from_product([["a", "b"], [0, 1]]) >>> xr.Coordinates.from_pandas_multiindex(midx, "x") Coordinates: - * x (x) object MultiIndex - * x_level_0 (x) object 'a' 'a' 'b' 'b' - * x_level_1 (x) int64 0 1 0 1 + * x (x) object 32B MultiIndex + * x_level_0 (x) object 32B 'a' 'a' 'b' 'b' + * x_level_1 (x) int64 32B 0 1 0 1 Create a new Dataset object by passing a Coordinates object: >>> midx_coords = xr.Coordinates.from_pandas_multiindex(midx, "x") >>> xr.Dataset(coords=midx_coords) - + Size: 96B Dimensions: (x: 4) Coordinates: - * x (x) object MultiIndex - * x_level_0 (x) object 'a' 'a' 'b' 'b' - * x_level_1 (x) int64 0 1 0 1 + * x (x) object 32B MultiIndex + * x_level_0 (x) object 32B 'a' 'a' 'b' 'b' + * x_level_1 (x) int64 32B 0 1 0 1 Data variables: *empty* @@ -602,14 +602,14 @@ def assign(self, coords: Mapping | None = None, **coords_kwargs: Any) -> Self: >>> coords.assign(x=[1, 2]) Coordinates: - * x (x) int64 1 2 + * x (x) int64 16B 1 2 >>> midx = pd.MultiIndex.from_product([["a", "b"], [0, 1]]) >>> coords.assign(xr.Coordinates.from_pandas_multiindex(midx, "y")) Coordinates: - * y (y) object MultiIndex - * y_level_0 (y) object 'a' 'a' 'b' 'b' - * y_level_1 (y) int64 0 1 0 1 + * y (y) object 32B MultiIndex + * y_level_0 (y) object 32B 'a' 'a' 'b' 'b' + * y_level_1 (y) int64 32B 0 1 0 1 """ # TODO: this doesn't support a callable, which is inconsistent with `DataArray.assign_coords` diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 3483f39f64a..763eab3a5ea 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -348,17 +348,17 @@ class DataArray( ... ), ... ) >>> da - + Size: 96B array([[[29.11241877, 18.20125767, 22.82990387], [32.92714559, 29.94046392, 7.18177696]], [[22.60070734, 13.78914233, 14.17424919], [18.28478802, 16.15234857, 26.63418806]]]) Coordinates: - lon (x, y) float64 -99.83 -99.32 -99.79 -99.23 - lat (x, y) float64 42.25 42.21 42.63 42.59 - * time (time) datetime64[ns] 2014-09-06 2014-09-07 2014-09-08 - reference_time datetime64[ns] 2014-09-05 + lon (x, y) float64 32B -99.83 -99.32 -99.79 -99.23 + lat (x, y) float64 32B 42.25 42.21 42.63 42.59 + * time (time) datetime64[ns] 24B 2014-09-06 2014-09-07 2014-09-08 + reference_time datetime64[ns] 8B 2014-09-05 Dimensions without coordinates: x, y Attributes: description: Ambient temperature. @@ -367,13 +367,13 @@ class DataArray( Find out where the coldest temperature was: >>> da.isel(da.argmin(...)) - + Size: 8B array(7.18177696) Coordinates: - lon float64 -99.32 - lat float64 42.21 - time datetime64[ns] 2014-09-08 - reference_time datetime64[ns] 2014-09-05 + lon float64 8B -99.32 + lat float64 8B 42.21 + time datetime64[ns] 8B 2014-09-08 + reference_time datetime64[ns] 8B 2014-09-05 Attributes: description: Ambient temperature. units: degC @@ -1021,43 +1021,43 @@ def reset_coords( ... name="Temperature", ... ) >>> da - + Size: 200B array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) Coordinates: - lon (x) int64 10 11 12 13 14 - lat (y) int64 20 21 22 23 24 - Pressure (x, y) int64 50 51 52 53 54 55 56 57 ... 67 68 69 70 71 72 73 74 + lon (x) int64 40B 10 11 12 13 14 + lat (y) int64 40B 20 21 22 23 24 + Pressure (x, y) int64 200B 50 51 52 53 54 55 56 57 ... 68 69 70 71 72 73 74 Dimensions without coordinates: x, y Return Dataset with target coordinate as a data variable rather than a coordinate variable: >>> da.reset_coords(names="Pressure") - + Size: 480B Dimensions: (x: 5, y: 5) Coordinates: - lon (x) int64 10 11 12 13 14 - lat (y) int64 20 21 22 23 24 + lon (x) int64 40B 10 11 12 13 14 + lat (y) int64 40B 20 21 22 23 24 Dimensions without coordinates: x, y Data variables: - Pressure (x, y) int64 50 51 52 53 54 55 56 57 ... 68 69 70 71 72 73 74 - Temperature (x, y) int64 0 1 2 3 4 5 6 7 8 9 ... 16 17 18 19 20 21 22 23 24 + Pressure (x, y) int64 200B 50 51 52 53 54 55 56 ... 68 69 70 71 72 73 74 + Temperature (x, y) int64 200B 0 1 2 3 4 5 6 7 8 ... 17 18 19 20 21 22 23 24 Return DataArray without targeted coordinate: >>> da.reset_coords(names="Pressure", drop=True) - + Size: 200B array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) Coordinates: - lon (x) int64 10 11 12 13 14 - lat (y) int64 20 21 22 23 24 + lon (x) int64 40B 10 11 12 13 14 + lat (y) int64 40B 20 21 22 23 24 Dimensions without coordinates: x, y """ if names is None: @@ -1207,37 +1207,37 @@ def copy(self, deep: bool = True, data: Any = None) -> Self: >>> array = xr.DataArray([1, 2, 3], dims="x", coords={"x": ["a", "b", "c"]}) >>> array.copy() - + Size: 24B array([1, 2, 3]) Coordinates: - * x (x) >> array_0 = array.copy(deep=False) >>> array_0[0] = 7 >>> array_0 - + Size: 24B array([7, 2, 3]) Coordinates: - * x (x) >> array - + Size: 24B array([7, 2, 3]) Coordinates: - * x (x) >> array.copy(data=[0.1, 0.2, 0.3]) - + Size: 24B array([0.1, 0.2, 0.3]) Coordinates: - * x (x) >> array - + Size: 24B array([7, 2, 3]) Coordinates: - * x (x) >> da = xr.DataArray(np.arange(25).reshape(5, 5), dims=("x", "y")) >>> da - + Size: 200B array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], @@ -1462,7 +1462,7 @@ def isel( >>> tgt_y = xr.DataArray(np.arange(0, 5), dims="points") >>> da = da.isel(x=tgt_x, y=tgt_y) >>> da - + Size: 40B array([ 0, 6, 12, 18, 24]) Dimensions without coordinates: points """ @@ -1592,25 +1592,25 @@ def sel( ... dims=("x", "y"), ... ) >>> da - + Size: 200B array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) Coordinates: - * x (x) int64 0 1 2 3 4 - * y (y) int64 0 1 2 3 4 + * x (x) int64 40B 0 1 2 3 4 + * y (y) int64 40B 0 1 2 3 4 >>> tgt_x = xr.DataArray(np.linspace(0, 4, num=5), dims="points") >>> tgt_y = xr.DataArray(np.linspace(0, 4, num=5), dims="points") >>> da = da.sel(x=tgt_x, y=tgt_y, method="nearest") >>> da - + Size: 40B array([ 0, 6, 12, 18, 24]) Coordinates: - x (points) int64 0 1 2 3 4 - y (points) int64 0 1 2 3 4 + x (points) int64 40B 0 1 2 3 4 + y (points) int64 40B 0 1 2 3 4 Dimensions without coordinates: points """ ds = self._to_temp_dataset().sel( @@ -1643,7 +1643,7 @@ def head( ... dims=("x", "y"), ... ) >>> da - + Size: 200B array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], @@ -1652,12 +1652,12 @@ def head( Dimensions without coordinates: x, y >>> da.head(x=1) - + Size: 40B array([[0, 1, 2, 3, 4]]) Dimensions without coordinates: x, y >>> da.head({"x": 2, "y": 2}) - + Size: 32B array([[0, 1], [5, 6]]) Dimensions without coordinates: x, y @@ -1686,7 +1686,7 @@ def tail( ... dims=("x", "y"), ... ) >>> da - + Size: 200B array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], @@ -1695,7 +1695,7 @@ def tail( Dimensions without coordinates: x, y >>> da.tail(y=1) - + Size: 40B array([[ 4], [ 9], [14], @@ -1704,7 +1704,7 @@ def tail( Dimensions without coordinates: x, y >>> da.tail({"x": 2, "y": 2}) - + Size: 32B array([[18, 19], [23, 24]]) Dimensions without coordinates: x, y @@ -1732,26 +1732,26 @@ def thin( ... coords={"x": [0, 1], "y": np.arange(0, 13)}, ... ) >>> x - + Size: 208B array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]]) Coordinates: - * x (x) int64 0 1 - * y (y) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 + * x (x) int64 16B 0 1 + * y (y) int64 104B 0 1 2 3 4 5 6 7 8 9 10 11 12 >>> >>> x.thin(3) - + Size: 40B array([[ 0, 3, 6, 9, 12]]) Coordinates: - * x (x) int64 0 - * y (y) int64 0 3 6 9 12 + * x (x) int64 8B 0 + * y (y) int64 40B 0 3 6 9 12 >>> x.thin({"x": 2, "y": 5}) - + Size: 24B array([[ 0, 5, 10]]) Coordinates: - * x (x) int64 0 - * y (y) int64 0 5 10 + * x (x) int64 8B 0 + * y (y) int64 24B 0 5 10 See Also -------- @@ -1807,28 +1807,28 @@ def broadcast_like( ... coords={"x": ["a", "b", "c"], "y": ["a", "b"]}, ... ) >>> arr1 - + Size: 48B array([[ 1.76405235, 0.40015721, 0.97873798], [ 2.2408932 , 1.86755799, -0.97727788]]) Coordinates: - * x (x) >> arr2 - + Size: 48B array([[ 0.95008842, -0.15135721], [-0.10321885, 0.4105985 ], [ 0.14404357, 1.45427351]]) Coordinates: - * x (x) >> arr1.broadcast_like(arr2) - + Size: 72B array([[ 1.76405235, 0.40015721, 0.97873798], [ 2.2408932 , 1.86755799, -0.97727788], [ nan, nan, nan]]) Coordinates: - * x (x) >> da1 - + Size: 96B array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) Coordinates: - * x (x) int64 10 20 30 40 - * y (y) int64 70 80 90 + * x (x) int64 32B 10 20 30 40 + * y (y) int64 24B 70 80 90 >>> da2 = xr.DataArray( ... data=data, ... dims=["x", "y"], ... coords={"x": [40, 30, 20, 10], "y": [90, 80, 70]}, ... ) >>> da2 - + Size: 96B array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) Coordinates: - * x (x) int64 40 30 20 10 - * y (y) int64 90 80 70 + * x (x) int64 32B 40 30 20 10 + * y (y) int64 24B 90 80 70 Reindexing with both DataArrays having the same coordinates set, but in different order: >>> da1.reindex_like(da2) - + Size: 96B array([[11, 10, 9], [ 8, 7, 6], [ 5, 4, 3], [ 2, 1, 0]]) Coordinates: - * x (x) int64 40 30 20 10 - * y (y) int64 90 80 70 + * x (x) int64 32B 40 30 20 10 + * y (y) int64 24B 90 80 70 Reindexing with the other array having additional coordinates: @@ -1984,68 +1984,68 @@ def reindex_like( ... coords={"x": [20, 10, 29, 39], "y": [70, 80, 90]}, ... ) >>> da1.reindex_like(da3) - + Size: 96B array([[ 3., 4., 5.], [ 0., 1., 2.], [nan, nan, nan], [nan, nan, nan]]) Coordinates: - * x (x) int64 20 10 29 39 - * y (y) int64 70 80 90 + * x (x) int64 32B 20 10 29 39 + * y (y) int64 24B 70 80 90 Filling missing values with the previous valid index with respect to the coordinates' value: >>> da1.reindex_like(da3, method="ffill") - + Size: 96B array([[3, 4, 5], [0, 1, 2], [3, 4, 5], [6, 7, 8]]) Coordinates: - * x (x) int64 20 10 29 39 - * y (y) int64 70 80 90 + * x (x) int64 32B 20 10 29 39 + * y (y) int64 24B 70 80 90 Filling missing values while tolerating specified error for inexact matches: >>> da1.reindex_like(da3, method="ffill", tolerance=5) - + Size: 96B array([[ 3., 4., 5.], [ 0., 1., 2.], [nan, nan, nan], [nan, nan, nan]]) Coordinates: - * x (x) int64 20 10 29 39 - * y (y) int64 70 80 90 + * x (x) int64 32B 20 10 29 39 + * y (y) int64 24B 70 80 90 Filling missing values with manually specified values: >>> da1.reindex_like(da3, fill_value=19) - + Size: 96B array([[ 3, 4, 5], [ 0, 1, 2], [19, 19, 19], [19, 19, 19]]) Coordinates: - * x (x) int64 20 10 29 39 - * y (y) int64 70 80 90 + * x (x) int64 32B 20 10 29 39 + * y (y) int64 24B 70 80 90 Note that unlike ``broadcast_like``, ``reindex_like`` doesn't create new dimensions: >>> da1.sel(x=20) - + Size: 24B array([3, 4, 5]) Coordinates: - x int64 20 - * y (y) int64 70 80 90 + x int64 8B 20 + * y (y) int64 24B 70 80 90 ...so ``b`` in not added here: >>> da1.sel(x=20).reindex_like(da1) - + Size: 24B array([3, 4, 5]) Coordinates: - x int64 20 - * y (y) int64 70 80 90 + x int64 8B 20 + * y (y) int64 24B 70 80 90 See Also -------- @@ -2130,15 +2130,15 @@ def reindex( ... dims="lat", ... ) >>> da - + Size: 32B array([0, 1, 2, 3]) Coordinates: - * lat (lat) int64 90 89 88 87 + * lat (lat) int64 32B 90 89 88 87 >>> da.reindex(lat=da.lat[::-1]) - + Size: 32B array([3, 2, 1, 0]) Coordinates: - * lat (lat) int64 87 88 89 90 + * lat (lat) int64 32B 87 88 89 90 See Also -------- @@ -2228,37 +2228,37 @@ def interp( ... coords={"x": [0, 1, 2], "y": [10, 12, 14, 16]}, ... ) >>> da - + Size: 96B array([[ 1., 4., 2., 9.], [ 2., 7., 6., nan], [ 6., nan, 5., 8.]]) Coordinates: - * x (x) int64 0 1 2 - * y (y) int64 10 12 14 16 + * x (x) int64 24B 0 1 2 + * y (y) int64 32B 10 12 14 16 1D linear interpolation (the default): >>> da.interp(x=[0, 0.75, 1.25, 1.75]) - + Size: 128B array([[1. , 4. , 2. , nan], [1.75, 6.25, 5. , nan], [3. , nan, 5.75, nan], [5. , nan, 5.25, nan]]) Coordinates: - * y (y) int64 10 12 14 16 - * x (x) float64 0.0 0.75 1.25 1.75 + * y (y) int64 32B 10 12 14 16 + * x (x) float64 32B 0.0 0.75 1.25 1.75 1D nearest interpolation: >>> da.interp(x=[0, 0.75, 1.25, 1.75], method="nearest") - + Size: 128B array([[ 1., 4., 2., 9.], [ 2., 7., 6., nan], [ 2., 7., 6., nan], [ 6., nan, 5., 8.]]) Coordinates: - * y (y) int64 10 12 14 16 - * x (x) float64 0.0 0.75 1.25 1.75 + * y (y) int64 32B 10 12 14 16 + * x (x) float64 32B 0.0 0.75 1.25 1.75 1D linear extrapolation: @@ -2267,26 +2267,26 @@ def interp( ... method="linear", ... kwargs={"fill_value": "extrapolate"}, ... ) - + Size: 128B array([[ 2. , 7. , 6. , nan], [ 4. , nan, 5.5, nan], [ 8. , nan, 4.5, nan], [12. , nan, 3.5, nan]]) Coordinates: - * y (y) int64 10 12 14 16 - * x (x) float64 1.0 1.5 2.5 3.5 + * y (y) int64 32B 10 12 14 16 + * x (x) float64 32B 1.0 1.5 2.5 3.5 2D linear interpolation: >>> da.interp(x=[0, 0.75, 1.25, 1.75], y=[11, 13, 15], method="linear") - + Size: 96B array([[2.5 , 3. , nan], [4. , 5.625, nan], [ nan, nan, nan], [ nan, nan, nan]]) Coordinates: - * x (x) float64 0.0 0.75 1.25 1.75 - * y (y) int64 11 13 15 + * x (x) float64 32B 0.0 0.75 1.25 1.75 + * y (y) int64 24B 11 13 15 """ if self.dtype.kind not in "uifc": raise TypeError( @@ -2357,52 +2357,52 @@ def interp_like( ... coords={"x": [10, 20, 30, 40], "y": [70, 80, 90]}, ... ) >>> da1 - + Size: 96B array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) Coordinates: - * x (x) int64 10 20 30 40 - * y (y) int64 70 80 90 + * x (x) int64 32B 10 20 30 40 + * y (y) int64 24B 70 80 90 >>> da2 = xr.DataArray( ... data=data, ... dims=["x", "y"], ... coords={"x": [10, 20, 29, 39], "y": [70, 80, 90]}, ... ) >>> da2 - + Size: 96B array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) Coordinates: - * x (x) int64 10 20 29 39 - * y (y) int64 70 80 90 + * x (x) int64 32B 10 20 29 39 + * y (y) int64 24B 70 80 90 Interpolate the values in the coordinates of the other DataArray with respect to the source's values: >>> da2.interp_like(da1) - + Size: 96B array([[0. , 1. , 2. ], [3. , 4. , 5. ], [6.3, 7.3, 8.3], [nan, nan, nan]]) Coordinates: - * x (x) int64 10 20 30 40 - * y (y) int64 70 80 90 + * x (x) int64 32B 10 20 30 40 + * y (y) int64 24B 70 80 90 Could also extrapolate missing values: >>> da2.interp_like(da1, kwargs={"fill_value": "extrapolate"}) - + Size: 96B array([[ 0. , 1. , 2. ], [ 3. , 4. , 5. ], [ 6.3, 7.3, 8.3], [ 9.3, 10.3, 11.3]]) Coordinates: - * x (x) int64 10 20 30 40 - * y (y) int64 70 80 90 + * x (x) int64 32B 10 20 30 40 + * y (y) int64 24B 70 80 90 Notes ----- @@ -2497,25 +2497,25 @@ def swap_dims( ... coords={"x": ["a", "b"], "y": ("x", [0, 1])}, ... ) >>> arr - + Size: 16B array([0, 1]) Coordinates: - * x (x) >> arr.swap_dims({"x": "y"}) - + Size: 16B array([0, 1]) Coordinates: - x (y) >> arr.swap_dims({"x": "z"}) - + Size: 16B array([0, 1]) Coordinates: - x (z) >> da = xr.DataArray(np.arange(5), dims=("x")) >>> da - + Size: 40B array([0, 1, 2, 3, 4]) Dimensions without coordinates: x Add new dimension of length 2: >>> da.expand_dims(dim={"y": 2}) - + Size: 80B array([[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]) Dimensions without coordinates: y, x >>> da.expand_dims(dim={"y": 2}, axis=1) - + Size: 80B array([[0, 0], [1, 1], [2, 2], @@ -2598,14 +2598,14 @@ def expand_dims( Add a new dimension with coordinates from array: >>> da.expand_dims(dim={"y": np.arange(5)}, axis=0) - + Size: 200B array([[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]) Coordinates: - * y (y) int64 0 1 2 3 4 + * y (y) int64 40B 0 1 2 3 4 Dimensions without coordinates: x """ if isinstance(dim, int): @@ -2661,20 +2661,20 @@ def set_index( ... coords={"x": range(2), "y": range(3), "a": ("x", [3, 4])}, ... ) >>> arr - + Size: 48B array([[1., 1., 1.], [1., 1., 1.]]) Coordinates: - * x (x) int64 0 1 - * y (y) int64 0 1 2 - a (x) int64 3 4 + * x (x) int64 16B 0 1 + * y (y) int64 24B 0 1 2 + a (x) int64 16B 3 4 >>> arr.set_index(x="a") - + Size: 48B array([[1., 1., 1.], [1., 1., 1.]]) Coordinates: - * x (x) int64 3 4 - * y (y) int64 0 1 2 + * x (x) int64 16B 3 4 + * y (y) int64 24B 0 1 2 See Also -------- @@ -2821,12 +2821,12 @@ def stack( ... coords=[("x", ["a", "b"]), ("y", [0, 1, 2])], ... ) >>> arr - + Size: 48B array([[0, 1, 2], [3, 4, 5]]) Coordinates: - * x (x) >> stacked = arr.stack(z=("x", "y")) >>> stacked.indexes["z"] MultiIndex([('a', 0), @@ -2888,12 +2888,12 @@ def unstack( ... coords=[("x", ["a", "b"]), ("y", [0, 1, 2])], ... ) >>> arr - + Size: 48B array([[0, 1, 2], [3, 4, 5]]) Coordinates: - * x (x) >> stacked = arr.stack(z=("x", "y")) >>> stacked.indexes["z"] MultiIndex([('a', 0), @@ -2940,14 +2940,14 @@ def to_unstacked_dataset(self, dim: Hashable, level: int | Hashable = 0) -> Data ... ) >>> data = xr.Dataset({"a": arr, "b": arr.isel(y=0)}) >>> data - + Size: 96B Dimensions: (x: 2, y: 3) Coordinates: - * x (x) >> stacked = data.to_stacked_array("z", ["x"]) >>> stacked.indexes["z"] MultiIndex([('a', 0), @@ -3065,31 +3065,31 @@ def drop_vars( ... coords={"x": [10, 20, 30, 40], "y": [70, 80, 90]}, ... ) >>> da - + Size: 96B array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) Coordinates: - * x (x) int64 10 20 30 40 - * y (y) int64 70 80 90 + * x (x) int64 32B 10 20 30 40 + * y (y) int64 24B 70 80 90 Removing a single variable: >>> da.drop_vars("x") - + Size: 96B array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) Coordinates: - * y (y) int64 70 80 90 + * y (y) int64 24B 70 80 90 Dimensions without coordinates: x Removing a list of variables: >>> da.drop_vars(["x", "y"]) - + Size: 96B array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], @@ -3097,7 +3097,7 @@ def drop_vars( Dimensions without coordinates: x, y >>> da.drop_vars(lambda x: x.coords) - + Size: 96B array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], @@ -3187,34 +3187,34 @@ def drop_sel( ... dims=("x", "y"), ... ) >>> da - + Size: 200B array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) Coordinates: - * x (x) int64 0 2 4 6 8 - * y (y) int64 0 3 6 9 12 + * x (x) int64 40B 0 2 4 6 8 + * y (y) int64 40B 0 3 6 9 12 >>> da.drop_sel(x=[0, 2], y=9) - + Size: 96B array([[10, 11, 12, 14], [15, 16, 17, 19], [20, 21, 22, 24]]) Coordinates: - * x (x) int64 4 6 8 - * y (y) int64 0 3 6 12 + * x (x) int64 24B 4 6 8 + * y (y) int64 32B 0 3 6 12 >>> da.drop_sel({"x": 6, "y": [0, 3]}) - + Size: 96B array([[ 2, 3, 4], [ 7, 8, 9], [12, 13, 14], [22, 23, 24]]) Coordinates: - * x (x) int64 0 2 4 8 - * y (y) int64 6 9 12 + * x (x) int64 32B 0 2 4 8 + * y (y) int64 24B 6 9 12 """ if labels_kwargs or isinstance(labels, dict): labels = either_dict_or_kwargs(labels, labels_kwargs, "drop") @@ -3246,7 +3246,7 @@ def drop_isel( -------- >>> da = xr.DataArray(np.arange(25).reshape(5, 5), dims=("X", "Y")) >>> da - + Size: 200B array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], @@ -3255,14 +3255,14 @@ def drop_isel( Dimensions without coordinates: X, Y >>> da.drop_isel(X=[0, 4], Y=2) - + Size: 96B array([[ 5, 6, 8, 9], [10, 11, 13, 14], [15, 16, 18, 19]]) Dimensions without coordinates: X, Y >>> da.drop_isel({"X": 3, "Y": 3}) - + Size: 128B array([[ 0, 1, 2, 4], [ 5, 6, 7, 9], [10, 11, 12, 14], @@ -3317,35 +3317,35 @@ def dropna( ... ), ... ) >>> da - + Size: 128B array([[ 0., 4., 2., 9.], [nan, nan, nan, nan], [nan, 4., 2., 0.], [ 3., 1., 0., 0.]]) Coordinates: - lat (Y) float64 -20.0 -20.25 -20.5 -20.75 - lon (X) float64 10.0 10.25 10.5 10.75 + lat (Y) float64 32B -20.0 -20.25 -20.5 -20.75 + lon (X) float64 32B 10.0 10.25 10.5 10.75 Dimensions without coordinates: Y, X >>> da.dropna(dim="Y", how="any") - + Size: 64B array([[0., 4., 2., 9.], [3., 1., 0., 0.]]) Coordinates: - lat (Y) float64 -20.0 -20.75 - lon (X) float64 10.0 10.25 10.5 10.75 + lat (Y) float64 16B -20.0 -20.75 + lon (X) float64 32B 10.0 10.25 10.5 10.75 Dimensions without coordinates: Y, X Drop values only if all values along the dimension are NaN: >>> da.dropna(dim="Y", how="all") - + Size: 96B array([[ 0., 4., 2., 9.], [nan, 4., 2., 0.], [ 3., 1., 0., 0.]]) Coordinates: - lat (Y) float64 -20.0 -20.5 -20.75 - lon (X) float64 10.0 10.25 10.5 10.75 + lat (Y) float64 24B -20.0 -20.5 -20.75 + lon (X) float64 32B 10.0 10.25 10.5 10.75 Dimensions without coordinates: Y, X """ ds = self._to_temp_dataset().dropna(dim, how=how, thresh=thresh) @@ -3381,29 +3381,29 @@ def fillna(self, value: Any) -> Self: ... ), ... ) >>> da - + Size: 48B array([ 1., 4., nan, 0., 3., nan]) Coordinates: - * Z (Z) int64 0 1 2 3 4 5 - height (Z) int64 0 10 20 30 40 50 + * Z (Z) int64 48B 0 1 2 3 4 5 + height (Z) int64 48B 0 10 20 30 40 50 Fill all NaN values with 0: >>> da.fillna(0) - + Size: 48B array([1., 4., 0., 0., 3., 0.]) Coordinates: - * Z (Z) int64 0 1 2 3 4 5 - height (Z) int64 0 10 20 30 40 50 + * Z (Z) int64 48B 0 1 2 3 4 5 + height (Z) int64 48B 0 10 20 30 40 50 Fill NaN values with corresponding values in array: >>> da.fillna(np.array([2, 9, 4, 2, 8, 9])) - + Size: 48B array([1., 4., 4., 0., 3., 9.]) Coordinates: - * Z (Z) int64 0 1 2 3 4 5 - height (Z) int64 0 10 20 30 40 50 + * Z (Z) int64 48B 0 1 2 3 4 5 + height (Z) int64 48B 0 10 20 30 40 50 """ if utils.is_dict_like(value): raise TypeError( @@ -3507,22 +3507,22 @@ def interpolate_na( ... [np.nan, 2, 3, np.nan, 0], dims="x", coords={"x": [0, 1, 2, 3, 4]} ... ) >>> da - + Size: 40B array([nan, 2., 3., nan, 0.]) Coordinates: - * x (x) int64 0 1 2 3 4 + * x (x) int64 40B 0 1 2 3 4 >>> da.interpolate_na(dim="x", method="linear") - + Size: 40B array([nan, 2. , 3. , 1.5, 0. ]) Coordinates: - * x (x) int64 0 1 2 3 4 + * x (x) int64 40B 0 1 2 3 4 >>> da.interpolate_na(dim="x", method="linear", fill_value="extrapolate") - + Size: 40B array([1. , 2. , 3. , 1.5, 0. ]) Coordinates: - * x (x) int64 0 1 2 3 4 + * x (x) int64 40B 0 1 2 3 4 """ from xarray.core.missing import interp_na @@ -3578,43 +3578,43 @@ def ffill(self, dim: Hashable, limit: int | None = None) -> Self: ... ), ... ) >>> da - + Size: 120B array([[nan, 1., 3.], [ 0., nan, 5.], [ 5., nan, nan], [ 3., nan, nan], [ 0., 2., 0.]]) Coordinates: - lat (Y) float64 -20.0 -20.25 -20.5 -20.75 -21.0 - lon (X) float64 10.0 10.25 10.5 + lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 + lon (X) float64 24B 10.0 10.25 10.5 Dimensions without coordinates: Y, X Fill all NaN values: >>> da.ffill(dim="Y", limit=None) - + Size: 120B array([[nan, 1., 3.], [ 0., 1., 5.], [ 5., 1., 5.], [ 3., 1., 5.], [ 0., 2., 0.]]) Coordinates: - lat (Y) float64 -20.0 -20.25 -20.5 -20.75 -21.0 - lon (X) float64 10.0 10.25 10.5 + lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 + lon (X) float64 24B 10.0 10.25 10.5 Dimensions without coordinates: Y, X Fill only the first of consecutive NaN values: >>> da.ffill(dim="Y", limit=1) - + Size: 120B array([[nan, 1., 3.], [ 0., 1., 5.], [ 5., nan, 5.], [ 3., nan, nan], [ 0., 2., 0.]]) Coordinates: - lat (Y) float64 -20.0 -20.25 -20.5 -20.75 -21.0 - lon (X) float64 10.0 10.25 10.5 + lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 + lon (X) float64 24B 10.0 10.25 10.5 Dimensions without coordinates: Y, X """ from xarray.core.missing import ffill @@ -3662,43 +3662,43 @@ def bfill(self, dim: Hashable, limit: int | None = None) -> Self: ... ), ... ) >>> da - + Size: 120B array([[ 0., 1., 3.], [ 0., nan, 5.], [ 5., nan, nan], [ 3., nan, nan], [nan, 2., 0.]]) Coordinates: - lat (Y) float64 -20.0 -20.25 -20.5 -20.75 -21.0 - lon (X) float64 10.0 10.25 10.5 + lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 + lon (X) float64 24B 10.0 10.25 10.5 Dimensions without coordinates: Y, X Fill all NaN values: >>> da.bfill(dim="Y", limit=None) - + Size: 120B array([[ 0., 1., 3.], [ 0., 2., 5.], [ 5., 2., 0.], [ 3., 2., 0.], [nan, 2., 0.]]) Coordinates: - lat (Y) float64 -20.0 -20.25 -20.5 -20.75 -21.0 - lon (X) float64 10.0 10.25 10.5 + lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 + lon (X) float64 24B 10.0 10.25 10.5 Dimensions without coordinates: Y, X Fill only the first of consecutive NaN values: >>> da.bfill(dim="Y", limit=1) - + Size: 120B array([[ 0., 1., 3.], [ 0., nan, 5.], [ 5., nan, nan], [ 3., 2., 0.], [nan, 2., 0.]]) Coordinates: - lat (Y) float64 -20.0 -20.25 -20.5 -20.75 -21.0 - lon (X) float64 10.0 10.25 10.5 + lat (Y) float64 40B -20.0 -20.25 -20.5 -20.75 -21.0 + lon (X) float64 24B 10.0 10.25 10.5 Dimensions without coordinates: Y, X """ from xarray.core.missing import bfill @@ -4369,7 +4369,7 @@ def from_dict(cls, d: Mapping[str, Any]) -> Self: >>> d = {"dims": "t", "data": [1, 2, 3]} >>> da = xr.DataArray.from_dict(d) >>> da - + Size: 24B array([1, 2, 3]) Dimensions without coordinates: t @@ -4384,10 +4384,10 @@ def from_dict(cls, d: Mapping[str, Any]) -> Self: ... } >>> da = xr.DataArray.from_dict(d) >>> da - + Size: 24B array([10, 20, 30]) Coordinates: - * t (t) int64 0 1 2 + * t (t) int64 24B 0 1 2 Attributes: title: air temperature """ @@ -4491,11 +4491,11 @@ def broadcast_equals(self, other: Self) -> bool: >>> a = xr.DataArray([1, 2], dims="X") >>> b = xr.DataArray([[1, 1], [2, 2]], dims=["X", "Y"]) >>> a - + Size: 16B array([1, 2]) Dimensions without coordinates: X >>> b - + Size: 32B array([[1, 1], [2, 2]]) Dimensions without coordinates: X, Y @@ -4547,21 +4547,21 @@ def equals(self, other: Self) -> bool: >>> c = xr.DataArray([1, 2, 3], dims="Y") >>> d = xr.DataArray([3, 2, 1], dims="X") >>> a - + Size: 24B array([1, 2, 3]) Dimensions without coordinates: X >>> b - + Size: 24B array([1, 2, 3]) Dimensions without coordinates: X Attributes: units: m >>> c - + Size: 24B array([1, 2, 3]) Dimensions without coordinates: Y >>> d - + Size: 24B array([3, 2, 1]) Dimensions without coordinates: X @@ -4602,19 +4602,19 @@ def identical(self, other: Self) -> bool: >>> b = xr.DataArray([1, 2, 3], dims="X", attrs=dict(units="m"), name="Width") >>> c = xr.DataArray([1, 2, 3], dims="X", attrs=dict(units="ft"), name="Width") >>> a - + Size: 24B array([1, 2, 3]) Dimensions without coordinates: X Attributes: units: m >>> b - + Size: 24B array([1, 2, 3]) Dimensions without coordinates: X Attributes: units: m >>> c - + Size: 24B array([1, 2, 3]) Dimensions without coordinates: X Attributes: @@ -4788,15 +4788,15 @@ def diff( -------- >>> arr = xr.DataArray([5, 5, 6, 6], [[1, 2, 3, 4]], ["x"]) >>> arr.diff("x") - + Size: 24B array([0, 1, 0]) Coordinates: - * x (x) int64 2 3 4 + * x (x) int64 24B 2 3 4 >>> arr.diff("x", 2) - + Size: 16B array([ 1, -1]) Coordinates: - * x (x) int64 3 4 + * x (x) int64 16B 3 4 See Also -------- @@ -4846,7 +4846,7 @@ def shift( -------- >>> arr = xr.DataArray([5, 6, 7], dims="x") >>> arr.shift(x=1) - + Size: 24B array([nan, 5., 6.]) Dimensions without coordinates: x """ @@ -4895,7 +4895,7 @@ def roll( -------- >>> arr = xr.DataArray([5, 6, 7], dims="x") >>> arr.roll(x=1) - + Size: 24B array([7, 5, 6]) Dimensions without coordinates: x """ @@ -5037,22 +5037,22 @@ def sortby( ... dims="time", ... ) >>> da - + Size: 40B array([5, 4, 3, 2, 1]) Coordinates: - * time (time) datetime64[ns] 2000-01-01 2000-01-02 ... 2000-01-05 + * time (time) datetime64[ns] 40B 2000-01-01 2000-01-02 ... 2000-01-05 >>> da.sortby(da) - + Size: 40B array([1, 2, 3, 4, 5]) Coordinates: - * time (time) datetime64[ns] 2000-01-05 2000-01-04 ... 2000-01-01 + * time (time) datetime64[ns] 40B 2000-01-05 2000-01-04 ... 2000-01-01 >>> da.sortby(lambda x: x) - + Size: 40B array([1, 2, 3, 4, 5]) Coordinates: - * time (time) datetime64[ns] 2000-01-05 2000-01-04 ... 2000-01-01 + * time (time) datetime64[ns] 40B 2000-01-05 2000-01-04 ... 2000-01-01 """ # We need to convert the callable here rather than pass it through to the # dataset method, since otherwise the dataset method would try to call the @@ -5141,29 +5141,29 @@ def quantile( ... dims=("x", "y"), ... ) >>> da.quantile(0) # or da.quantile(0, dim=...) - + Size: 8B array(0.7) Coordinates: - quantile float64 0.0 + quantile float64 8B 0.0 >>> da.quantile(0, dim="x") - + Size: 32B array([0.7, 4.2, 2.6, 1.5]) Coordinates: - * y (y) float64 1.0 1.5 2.0 2.5 - quantile float64 0.0 + * y (y) float64 32B 1.0 1.5 2.0 2.5 + quantile float64 8B 0.0 >>> da.quantile([0, 0.5, 1]) - + Size: 24B array([0.7, 3.4, 9.4]) Coordinates: - * quantile (quantile) float64 0.0 0.5 1.0 + * quantile (quantile) float64 24B 0.0 0.5 1.0 >>> da.quantile([0, 0.5, 1], dim="x") - + Size: 96B array([[0.7 , 4.2 , 2.6 , 1.5 ], [3.6 , 5.75, 6. , 1.7 ], [6.5 , 7.3 , 9.4 , 1.9 ]]) Coordinates: - * y (y) float64 1.0 1.5 2.0 2.5 - * quantile (quantile) float64 0.0 0.5 1.0 + * y (y) float64 32B 1.0 1.5 2.0 2.5 + * quantile (quantile) float64 24B 0.0 0.5 1.0 References ---------- @@ -5220,7 +5220,7 @@ def rank( -------- >>> arr = xr.DataArray([5, 6, 7], dims="x") >>> arr.rank("x") - + Size: 24B array([1., 2., 3.]) Dimensions without coordinates: x """ @@ -5269,23 +5269,23 @@ def differentiate( ... coords={"x": [0, 0.1, 1.1, 1.2]}, ... ) >>> da - + Size: 96B array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) Coordinates: - * x (x) float64 0.0 0.1 1.1 1.2 + * x (x) float64 32B 0.0 0.1 1.1 1.2 Dimensions without coordinates: y >>> >>> da.differentiate("x") - + Size: 96B array([[30. , 30. , 30. ], [27.54545455, 27.54545455, 27.54545455], [27.54545455, 27.54545455, 27.54545455], [30. , 30. , 30. ]]) Coordinates: - * x (x) float64 0.0 0.1 1.1 1.2 + * x (x) float64 32B 0.0 0.1 1.1 1.2 Dimensions without coordinates: y """ ds = self._to_temp_dataset().differentiate(coord, edge_order, datetime_unit) @@ -5328,17 +5328,17 @@ def integrate( ... coords={"x": [0, 0.1, 1.1, 1.2]}, ... ) >>> da - + Size: 96B array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) Coordinates: - * x (x) float64 0.0 0.1 1.1 1.2 + * x (x) float64 32B 0.0 0.1 1.1 1.2 Dimensions without coordinates: y >>> >>> da.integrate("x") - + Size: 24B array([5.4, 6.6, 7.8]) Dimensions without coordinates: y """ @@ -5385,23 +5385,23 @@ def cumulative_integrate( ... coords={"x": [0, 0.1, 1.1, 1.2]}, ... ) >>> da - + Size: 96B array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) Coordinates: - * x (x) float64 0.0 0.1 1.1 1.2 + * x (x) float64 32B 0.0 0.1 1.1 1.2 Dimensions without coordinates: y >>> >>> da.cumulative_integrate("x") - + Size: 96B array([[0. , 0. , 0. ], [0.15, 0.25, 0.35], [4.65, 5.75, 6.85], [5.4 , 6.6 , 7.8 ]]) Coordinates: - * x (x) float64 0.0 0.1 1.1 1.2 + * x (x) float64 32B 0.0 0.1 1.1 1.2 Dimensions without coordinates: y """ ds = self._to_temp_dataset().cumulative_integrate(coord, datetime_unit) @@ -5502,15 +5502,15 @@ def map_blocks( ... coords={"time": time, "month": month}, ... ).chunk() >>> array.map_blocks(calculate_anomaly, template=array).compute() - + Size: 192B array([ 0.12894847, 0.11323072, -0.0855964 , -0.09334032, 0.26848862, 0.12382735, 0.22460641, 0.07650108, -0.07673453, -0.22865714, -0.19063865, 0.0590131 , -0.12894847, -0.11323072, 0.0855964 , 0.09334032, -0.26848862, -0.12382735, -0.22460641, -0.07650108, 0.07673453, 0.22865714, 0.19063865, -0.0590131 ]) Coordinates: - * time (time) object 1990-01-31 00:00:00 ... 1991-12-31 00:00:00 - month (time) int64 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 + * time (time) object 192B 1990-01-31 00:00:00 ... 1991-12-31 00:00:00 + month (time) int64 192B 1 2 3 4 5 6 7 8 9 10 ... 3 4 5 6 7 8 9 10 11 12 Note that one must explicitly use ``args=[]`` and ``kwargs={}`` to pass arguments to the function being applied in ``xr.map_blocks()``: @@ -5518,11 +5518,11 @@ def map_blocks( >>> array.map_blocks( ... calculate_anomaly, kwargs={"groupby_type": "time.year"}, template=array ... ) # doctest: +ELLIPSIS - + Size: 192B dask.array<-calculate_anomaly, shape=(24,), dtype=float64, chunksize=(24,), chunktype=numpy.ndarray> Coordinates: - * time (time) object 1990-01-31 00:00:00 ... 1991-12-31 00:00:00 - month (time) int64 dask.array + * time (time) object 192B 1990-01-31 00:00:00 ... 1991-12-31 00:00:00 + month (time) int64 192B dask.array """ from xarray.core.parallel import map_blocks @@ -5713,10 +5713,10 @@ def pad( -------- >>> arr = xr.DataArray([5, 6, 7], coords=[("x", [0, 1, 2])]) >>> arr.pad(x=(1, 2), constant_values=0) - + Size: 48B array([0, 5, 6, 7, 0, 0]) Coordinates: - * x (x) float64 nan 0.0 1.0 2.0 nan nan + * x (x) float64 48B nan 0.0 1.0 2.0 nan nan >>> da = xr.DataArray( ... [[0, 1, 2, 3], [10, 11, 12, 13]], @@ -5724,29 +5724,29 @@ def pad( ... coords={"x": [0, 1], "y": [10, 20, 30, 40], "z": ("x", [100, 200])}, ... ) >>> da.pad(x=1) - + Size: 128B array([[nan, nan, nan, nan], [ 0., 1., 2., 3.], [10., 11., 12., 13.], [nan, nan, nan, nan]]) Coordinates: - * x (x) float64 nan 0.0 1.0 nan - * y (y) int64 10 20 30 40 - z (x) float64 nan 100.0 200.0 nan + * x (x) float64 32B nan 0.0 1.0 nan + * y (y) int64 32B 10 20 30 40 + z (x) float64 32B nan 100.0 200.0 nan Careful, ``constant_values`` are coerced to the data type of the array which may lead to a loss of precision: >>> da.pad(x=1, constant_values=1.23456789) - + Size: 128B array([[ 1, 1, 1, 1], [ 0, 1, 2, 3], [10, 11, 12, 13], [ 1, 1, 1, 1]]) Coordinates: - * x (x) float64 nan 0.0 1.0 nan - * y (y) int64 10 20 30 40 - z (x) float64 nan 100.0 200.0 nan + * x (x) float64 32B nan 0.0 1.0 nan + * y (y) int64 32B 10 20 30 40 + z (x) float64 32B nan 100.0 200.0 nan """ ds = self._to_temp_dataset().pad( pad_width=pad_width, @@ -5815,13 +5815,13 @@ def idxmin( ... [0, 2, 1, 0, -2], dims="x", coords={"x": ["a", "b", "c", "d", "e"]} ... ) >>> array.min() - + Size: 8B array(-2) >>> array.argmin(...) - {'x': + {'x': Size: 8B array(4)} >>> array.idxmin() - + Size: 4B array('e', dtype='>> array = xr.DataArray( @@ -5834,20 +5834,20 @@ def idxmin( ... coords={"y": [-1, 0, 1], "x": np.arange(5.0) ** 2}, ... ) >>> array.min(dim="x") - + Size: 24B array([-2., -4., 1.]) Coordinates: - * y (y) int64 -1 0 1 + * y (y) int64 24B -1 0 1 >>> array.argmin(dim="x") - + Size: 24B array([4, 0, 2]) Coordinates: - * y (y) int64 -1 0 1 + * y (y) int64 24B -1 0 1 >>> array.idxmin(dim="x") - + Size: 24B array([16., 0., 4.]) Coordinates: - * y (y) int64 -1 0 1 + * y (y) int64 24B -1 0 1 """ return computation._calc_idxminmax( array=self, @@ -5913,13 +5913,13 @@ def idxmax( ... [0, 2, 1, 0, -2], dims="x", coords={"x": ["a", "b", "c", "d", "e"]} ... ) >>> array.max() - + Size: 8B array(2) >>> array.argmax(...) - {'x': + {'x': Size: 8B array(1)} >>> array.idxmax() - + Size: 4B array('b', dtype='>> array = xr.DataArray( @@ -5932,20 +5932,20 @@ def idxmax( ... coords={"y": [-1, 0, 1], "x": np.arange(5.0) ** 2}, ... ) >>> array.max(dim="x") - + Size: 24B array([2., 2., 1.]) Coordinates: - * y (y) int64 -1 0 1 + * y (y) int64 24B -1 0 1 >>> array.argmax(dim="x") - + Size: 24B array([0, 2, 2]) Coordinates: - * y (y) int64 -1 0 1 + * y (y) int64 24B -1 0 1 >>> array.idxmax(dim="x") - + Size: 24B array([0., 4., 4.]) Coordinates: - * y (y) int64 -1 0 1 + * y (y) int64 24B -1 0 1 """ return computation._calc_idxminmax( array=self, @@ -6006,13 +6006,13 @@ def argmin( -------- >>> array = xr.DataArray([0, 2, -1, 3], dims="x") >>> array.min() - + Size: 8B array(-1) >>> array.argmin(...) - {'x': + {'x': Size: 8B array(2)} >>> array.isel(array.argmin(...)) - + Size: 8B array(-1) >>> array = xr.DataArray( @@ -6020,35 +6020,35 @@ def argmin( ... dims=("x", "y", "z"), ... ) >>> array.min(dim="x") - + Size: 72B array([[ 1, 2, 1], [ 2, -5, 1], [ 2, 1, 1]]) Dimensions without coordinates: y, z >>> array.argmin(dim="x") - + Size: 72B array([[1, 0, 0], [1, 1, 1], [0, 0, 1]]) Dimensions without coordinates: y, z >>> array.argmin(dim=["x"]) - {'x': + {'x': Size: 72B array([[1, 0, 0], [1, 1, 1], [0, 0, 1]]) Dimensions without coordinates: y, z} >>> array.min(dim=("x", "z")) - + Size: 24B array([ 1, -5, 1]) Dimensions without coordinates: y >>> array.argmin(dim=["x", "z"]) - {'x': + {'x': Size: 24B array([0, 1, 0]) - Dimensions without coordinates: y, 'z': + Dimensions without coordinates: y, 'z': Size: 24B array([2, 1, 1]) Dimensions without coordinates: y} >>> array.isel(array.argmin(dim=["x", "z"])) - + Size: 24B array([ 1, -5, 1]) Dimensions without coordinates: y """ @@ -6108,13 +6108,13 @@ def argmax( -------- >>> array = xr.DataArray([0, 2, -1, 3], dims="x") >>> array.max() - + Size: 8B array(3) >>> array.argmax(...) - {'x': + {'x': Size: 8B array(3)} >>> array.isel(array.argmax(...)) - + Size: 8B array(3) >>> array = xr.DataArray( @@ -6122,35 +6122,35 @@ def argmax( ... dims=("x", "y", "z"), ... ) >>> array.max(dim="x") - + Size: 72B array([[3, 3, 2], [3, 5, 2], [2, 3, 3]]) Dimensions without coordinates: y, z >>> array.argmax(dim="x") - + Size: 72B array([[0, 1, 1], [0, 1, 0], [0, 1, 0]]) Dimensions without coordinates: y, z >>> array.argmax(dim=["x"]) - {'x': + {'x': Size: 72B array([[0, 1, 1], [0, 1, 0], [0, 1, 0]]) Dimensions without coordinates: y, z} >>> array.max(dim=("x", "z")) - + Size: 24B array([3, 5, 3]) Dimensions without coordinates: y >>> array.argmax(dim=["x", "z"]) - {'x': + {'x': Size: 24B array([0, 1, 0]) - Dimensions without coordinates: y, 'z': + Dimensions without coordinates: y, 'z': Size: 24B array([0, 1, 2]) Dimensions without coordinates: y} >>> array.isel(array.argmax(dim=["x", "z"])) - + Size: 24B array([3, 5, 3]) Dimensions without coordinates: y """ @@ -6220,11 +6220,11 @@ def query( -------- >>> da = xr.DataArray(np.arange(0, 5, 1), dims="x", name="a") >>> da - + Size: 40B array([0, 1, 2, 3, 4]) Dimensions without coordinates: x >>> da.query(x="a > 2") - + Size: 16B array([3, 4]) Dimensions without coordinates: x """ @@ -6332,7 +6332,7 @@ def curvefit( ... coords={"x": [0, 1, 2], "time": t}, ... ) >>> da - + Size: 264B array([[ 0.1012573 , 0.0354669 , 0.01993775, 0.00602771, -0.00352513, 0.00428975, 0.01328788, 0.009562 , -0.00700381, -0.01264187, -0.0062282 ], @@ -6343,8 +6343,8 @@ def curvefit( 0.04744543, 0.03602333, 0.03129354, 0.01074885, 0.01284436, 0.00910995]]) Coordinates: - * x (x) int64 0 1 2 - * time (time) int64 0 1 2 3 4 5 6 7 8 9 10 + * x (x) int64 24B 0 1 2 + * time (time) int64 88B 0 1 2 3 4 5 6 7 8 9 10 Fit the exponential decay function to the data along the ``time`` dimension: @@ -6352,17 +6352,17 @@ def curvefit( >>> fit_result["curvefit_coefficients"].sel( ... param="time_constant" ... ) # doctest: +NUMBER - + Size: 24B array([1.05692036, 1.73549638, 2.94215771]) Coordinates: - * x (x) int64 0 1 2 - param >> fit_result["curvefit_coefficients"].sel(param="amplitude") - + Size: 24B array([0.1005489 , 0.19631423, 0.30003579]) Coordinates: - * x (x) int64 0 1 2 - param >> fit_result["curvefit_coefficients"].sel(param="time_constant") - + Size: 24B array([1.0569213 , 1.73550052, 2.94215733]) Coordinates: - * x (x) int64 0 1 2 - param >> fit_result["curvefit_coefficients"].sel(param="amplitude") - + Size: 24B array([0.10054889, 0.1963141 , 0.3000358 ]) Coordinates: - * x (x) int64 0 1 2 - param >> da - + Size: 200B array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) Coordinates: - * x (x) int64 0 0 1 2 3 - * y (y) int64 0 1 2 3 3 + * x (x) int64 40B 0 0 1 2 3 + * y (y) int64 40B 0 1 2 3 3 >>> da.drop_duplicates(dim="x") - + Size: 160B array([[ 0, 1, 2, 3, 4], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) Coordinates: - * x (x) int64 0 1 2 3 - * y (y) int64 0 1 2 3 3 + * x (x) int64 32B 0 1 2 3 + * y (y) int64 40B 0 1 2 3 3 >>> da.drop_duplicates(dim="x", keep="last") - + Size: 160B array([[ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) Coordinates: - * x (x) int64 0 1 2 3 - * y (y) int64 0 1 2 3 3 + * x (x) int64 32B 0 1 2 3 + * y (y) int64 40B 0 1 2 3 3 Drop all duplicate dimension values: >>> da.drop_duplicates(dim=...) - + Size: 128B array([[ 0, 1, 2, 3], [10, 11, 12, 13], [15, 16, 17, 18], [20, 21, 22, 23]]) Coordinates: - * x (x) int64 0 1 2 3 - * y (y) int64 0 1 2 3 + * x (x) int64 32B 0 1 2 3 + * y (y) int64 32B 0 1 2 3 """ deduplicated = self._to_temp_dataset().drop_duplicates(dim, keep=keep) return self._from_temp_dataset(deduplicated) @@ -6679,17 +6679,17 @@ def groupby( ... dims="time", ... ) >>> da - + Size: 15kB array([0.000e+00, 1.000e+00, 2.000e+00, ..., 1.824e+03, 1.825e+03, 1.826e+03]) Coordinates: - * time (time) datetime64[ns] 2000-01-01 2000-01-02 ... 2004-12-31 + * time (time) datetime64[ns] 15kB 2000-01-01 2000-01-02 ... 2004-12-31 >>> da.groupby("time.dayofyear") - da.groupby("time.dayofyear").mean("time") - + Size: 15kB array([-730.8, -730.8, -730.8, ..., 730.2, 730.2, 730.5]) Coordinates: - * time (time) datetime64[ns] 2000-01-01 2000-01-02 ... 2004-12-31 - dayofyear (time) int64 1 2 3 4 5 6 7 8 ... 359 360 361 362 363 364 365 366 + * time (time) datetime64[ns] 15kB 2000-01-01 2000-01-02 ... 2004-12-31 + dayofyear (time) int64 15kB 1 2 3 4 5 6 7 8 ... 360 361 362 363 364 365 366 See Also -------- @@ -6900,23 +6900,23 @@ def rolling( ... dims="time", ... ) >>> da - + Size: 96B array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.]) Coordinates: - * time (time) datetime64[ns] 1999-12-15 2000-01-15 ... 2000-11-15 + * time (time) datetime64[ns] 96B 1999-12-15 2000-01-15 ... 2000-11-15 >>> da.rolling(time=3, center=True).mean() - + Size: 96B array([nan, 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., nan]) Coordinates: - * time (time) datetime64[ns] 1999-12-15 2000-01-15 ... 2000-11-15 + * time (time) datetime64[ns] 96B 1999-12-15 2000-01-15 ... 2000-11-15 Remove the NaNs using ``dropna()``: >>> da.rolling(time=3, center=True).mean().dropna("time") - + Size: 80B array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) Coordinates: - * time (time) datetime64[ns] 2000-01-15 2000-02-15 ... 2000-10-15 + * time (time) datetime64[ns] 80B 2000-01-15 2000-02-15 ... 2000-10-15 See Also -------- @@ -6967,16 +6967,16 @@ def cumulative( ... ) >>> da - + Size: 96B array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.]) Coordinates: - * time (time) datetime64[ns] 1999-12-15 2000-01-15 ... 2000-11-15 + * time (time) datetime64[ns] 96B 1999-12-15 2000-01-15 ... 2000-11-15 >>> da.cumulative("time").sum() - + Size: 96B array([ 0., 1., 3., 6., 10., 15., 21., 28., 36., 45., 55., 66.]) Coordinates: - * time (time) datetime64[ns] 1999-12-15 2000-01-15 ... 2000-11-15 + * time (time) datetime64[ns] 96B 1999-12-15 2000-01-15 ... 2000-11-15 See Also -------- @@ -7042,25 +7042,85 @@ def coarsen( ... coords={"time": pd.date_range("1999-12-15", periods=364)}, ... ) >>> da # +doctest: ELLIPSIS - + Size: 3kB array([ 0. , 1.00275482, 2.00550964, 3.00826446, 4.01101928, 5.0137741 , 6.01652893, 7.01928375, 8.02203857, 9.02479339, 10.02754821, 11.03030303, + 12.03305785, 13.03581267, 14.03856749, 15.04132231, + 16.04407713, 17.04683196, 18.04958678, 19.0523416 , + 20.05509642, 21.05785124, 22.06060606, 23.06336088, + 24.0661157 , 25.06887052, 26.07162534, 27.07438017, + 28.07713499, 29.07988981, 30.08264463, 31.08539945, + 32.08815427, 33.09090909, 34.09366391, 35.09641873, + 36.09917355, 37.10192837, 38.1046832 , 39.10743802, + 40.11019284, 41.11294766, 42.11570248, 43.1184573 , + 44.12121212, 45.12396694, 46.12672176, 47.12947658, + 48.1322314 , 49.13498623, 50.13774105, 51.14049587, + 52.14325069, 53.14600551, 54.14876033, 55.15151515, + 56.15426997, 57.15702479, 58.15977961, 59.16253444, + 60.16528926, 61.16804408, 62.1707989 , 63.17355372, + 64.17630854, 65.17906336, 66.18181818, 67.184573 , + 68.18732782, 69.19008264, 70.19283747, 71.19559229, + 72.19834711, 73.20110193, 74.20385675, 75.20661157, + 76.20936639, 77.21212121, 78.21487603, 79.21763085, ... + 284.78236915, 285.78512397, 286.78787879, 287.79063361, + 288.79338843, 289.79614325, 290.79889807, 291.80165289, + 292.80440771, 293.80716253, 294.80991736, 295.81267218, + 296.815427 , 297.81818182, 298.82093664, 299.82369146, + 300.82644628, 301.8292011 , 302.83195592, 303.83471074, + 304.83746556, 305.84022039, 306.84297521, 307.84573003, + 308.84848485, 309.85123967, 310.85399449, 311.85674931, + 312.85950413, 313.86225895, 314.86501377, 315.8677686 , + 316.87052342, 317.87327824, 318.87603306, 319.87878788, + 320.8815427 , 321.88429752, 322.88705234, 323.88980716, + 324.89256198, 325.8953168 , 326.89807163, 327.90082645, + 328.90358127, 329.90633609, 330.90909091, 331.91184573, + 332.91460055, 333.91735537, 334.92011019, 335.92286501, + 336.92561983, 337.92837466, 338.93112948, 339.9338843 , + 340.93663912, 341.93939394, 342.94214876, 343.94490358, + 344.9476584 , 345.95041322, 346.95316804, 347.95592287, + 348.95867769, 349.96143251, 350.96418733, 351.96694215, + 352.96969697, 353.97245179, 354.97520661, 355.97796143, 356.98071625, 357.98347107, 358.9862259 , 359.98898072, 360.99173554, 361.99449036, 362.99724518, 364. ]) Coordinates: - * time (time) datetime64[ns] 1999-12-15 1999-12-16 ... 2000-12-12 + * time (time) datetime64[ns] 3kB 1999-12-15 1999-12-16 ... 2000-12-12 >>> da.coarsen(time=3, boundary="trim").mean() # +doctest: ELLIPSIS - + Size: 968B array([ 1.00275482, 4.01101928, 7.01928375, 10.02754821, 13.03581267, 16.04407713, 19.0523416 , 22.06060606, 25.06887052, 28.07713499, 31.08539945, 34.09366391, - ... + 37.10192837, 40.11019284, 43.1184573 , 46.12672176, + 49.13498623, 52.14325069, 55.15151515, 58.15977961, + 61.16804408, 64.17630854, 67.184573 , 70.19283747, + 73.20110193, 76.20936639, 79.21763085, 82.22589532, + 85.23415978, 88.24242424, 91.25068871, 94.25895317, + 97.26721763, 100.27548209, 103.28374656, 106.29201102, + 109.30027548, 112.30853994, 115.31680441, 118.32506887, + 121.33333333, 124.3415978 , 127.34986226, 130.35812672, + 133.36639118, 136.37465565, 139.38292011, 142.39118457, + 145.39944904, 148.4077135 , 151.41597796, 154.42424242, + 157.43250689, 160.44077135, 163.44903581, 166.45730028, + 169.46556474, 172.4738292 , 175.48209366, 178.49035813, + 181.49862259, 184.50688705, 187.51515152, 190.52341598, + 193.53168044, 196.5399449 , 199.54820937, 202.55647383, + 205.56473829, 208.57300275, 211.58126722, 214.58953168, + 217.59779614, 220.60606061, 223.61432507, 226.62258953, + 229.63085399, 232.63911846, 235.64738292, 238.65564738, + 241.66391185, 244.67217631, 247.68044077, 250.68870523, + 253.6969697 , 256.70523416, 259.71349862, 262.72176309, + 265.73002755, 268.73829201, 271.74655647, 274.75482094, + 277.7630854 , 280.77134986, 283.77961433, 286.78787879, + 289.79614325, 292.80440771, 295.81267218, 298.82093664, + 301.8292011 , 304.83746556, 307.84573003, 310.85399449, + 313.86225895, 316.87052342, 319.87878788, 322.88705234, + 325.8953168 , 328.90358127, 331.91184573, 334.92011019, + 337.92837466, 340.93663912, 343.94490358, 346.95316804, 349.96143251, 352.96969697, 355.97796143, 358.9862259 , 361.99449036]) Coordinates: - * time (time) datetime64[ns] 1999-12-16 1999-12-19 ... 2000-12-10 + * time (time) datetime64[ns] 968B 1999-12-16 1999-12-19 ... 2000-12-10 >>> See Also @@ -7173,36 +7233,96 @@ def resample( ... dims="time", ... ) >>> da - + Size: 96B array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.]) Coordinates: - * time (time) datetime64[ns] 1999-12-15 2000-01-15 ... 2000-11-15 + * time (time) datetime64[ns] 96B 1999-12-15 2000-01-15 ... 2000-11-15 >>> da.resample(time="QS-DEC").mean() - + Size: 32B array([ 1., 4., 7., 10.]) Coordinates: - * time (time) datetime64[ns] 1999-12-01 2000-03-01 2000-06-01 2000-09-01 + * time (time) datetime64[ns] 32B 1999-12-01 2000-03-01 ... 2000-09-01 Upsample monthly time-series data to daily data: >>> da.resample(time="1D").interpolate("linear") # +doctest: ELLIPSIS - + Size: 3kB array([ 0. , 0.03225806, 0.06451613, 0.09677419, 0.12903226, 0.16129032, 0.19354839, 0.22580645, 0.25806452, 0.29032258, 0.32258065, 0.35483871, 0.38709677, 0.41935484, 0.4516129 , + 0.48387097, 0.51612903, 0.5483871 , 0.58064516, 0.61290323, + 0.64516129, 0.67741935, 0.70967742, 0.74193548, 0.77419355, + 0.80645161, 0.83870968, 0.87096774, 0.90322581, 0.93548387, + 0.96774194, 1. , 1.03225806, 1.06451613, 1.09677419, + 1.12903226, 1.16129032, 1.19354839, 1.22580645, 1.25806452, + 1.29032258, 1.32258065, 1.35483871, 1.38709677, 1.41935484, + 1.4516129 , 1.48387097, 1.51612903, 1.5483871 , 1.58064516, + 1.61290323, 1.64516129, 1.67741935, 1.70967742, 1.74193548, + 1.77419355, 1.80645161, 1.83870968, 1.87096774, 1.90322581, + 1.93548387, 1.96774194, 2. , 2.03448276, 2.06896552, + 2.10344828, 2.13793103, 2.17241379, 2.20689655, 2.24137931, + 2.27586207, 2.31034483, 2.34482759, 2.37931034, 2.4137931 , + 2.44827586, 2.48275862, 2.51724138, 2.55172414, 2.5862069 , + 2.62068966, 2.65517241, 2.68965517, 2.72413793, 2.75862069, + 2.79310345, 2.82758621, 2.86206897, 2.89655172, 2.93103448, + 2.96551724, 3. , 3.03225806, 3.06451613, 3.09677419, + 3.12903226, 3.16129032, 3.19354839, 3.22580645, 3.25806452, ... + 7.87096774, 7.90322581, 7.93548387, 7.96774194, 8. , + 8.03225806, 8.06451613, 8.09677419, 8.12903226, 8.16129032, + 8.19354839, 8.22580645, 8.25806452, 8.29032258, 8.32258065, + 8.35483871, 8.38709677, 8.41935484, 8.4516129 , 8.48387097, + 8.51612903, 8.5483871 , 8.58064516, 8.61290323, 8.64516129, + 8.67741935, 8.70967742, 8.74193548, 8.77419355, 8.80645161, + 8.83870968, 8.87096774, 8.90322581, 8.93548387, 8.96774194, + 9. , 9.03333333, 9.06666667, 9.1 , 9.13333333, + 9.16666667, 9.2 , 9.23333333, 9.26666667, 9.3 , + 9.33333333, 9.36666667, 9.4 , 9.43333333, 9.46666667, + 9.5 , 9.53333333, 9.56666667, 9.6 , 9.63333333, + 9.66666667, 9.7 , 9.73333333, 9.76666667, 9.8 , + 9.83333333, 9.86666667, 9.9 , 9.93333333, 9.96666667, + 10. , 10.03225806, 10.06451613, 10.09677419, 10.12903226, + 10.16129032, 10.19354839, 10.22580645, 10.25806452, 10.29032258, + 10.32258065, 10.35483871, 10.38709677, 10.41935484, 10.4516129 , + 10.48387097, 10.51612903, 10.5483871 , 10.58064516, 10.61290323, + 10.64516129, 10.67741935, 10.70967742, 10.74193548, 10.77419355, 10.80645161, 10.83870968, 10.87096774, 10.90322581, 10.93548387, 10.96774194, 11. ]) Coordinates: - * time (time) datetime64[ns] 1999-12-15 1999-12-16 ... 2000-11-15 + * time (time) datetime64[ns] 3kB 1999-12-15 1999-12-16 ... 2000-11-15 Limit scope of upsampling method >>> da.resample(time="1D").nearest(tolerance="1D") - - array([ 0., 0., nan, ..., nan, 11., 11.]) + Size: 3kB + array([ 0., 0., nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, 1., 1., 1., nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, 2., 2., 2., nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 3., + 3., 3., nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, 4., 4., 4., nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, 5., 5., 5., nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + 6., 6., 6., nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, 7., 7., 7., nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, 8., 8., 8., nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, 9., 9., 9., nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, 10., 10., 10., nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, + nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, 11., 11.]) Coordinates: - * time (time) datetime64[ns] 1999-12-15 1999-12-16 ... 2000-11-15 + * time (time) datetime64[ns] 3kB 1999-12-15 1999-12-16 ... 2000-11-15 See Also -------- diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index c239648a6d2..2656fcf2667 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -614,17 +614,17 @@ class Dataset( ... attrs=dict(description="Weather related data."), ... ) >>> ds - + Size: 288B Dimensions: (x: 2, y: 2, time: 3) Coordinates: - lon (x, y) float64 -99.83 -99.32 -99.79 -99.23 - lat (x, y) float64 42.25 42.21 42.63 42.59 - * time (time) datetime64[ns] 2014-09-06 2014-09-07 2014-09-08 - reference_time datetime64[ns] 2014-09-05 + lon (x, y) float64 32B -99.83 -99.32 -99.79 -99.23 + lat (x, y) float64 32B 42.25 42.21 42.63 42.59 + * time (time) datetime64[ns] 24B 2014-09-06 2014-09-07 2014-09-08 + reference_time datetime64[ns] 8B 2014-09-05 Dimensions without coordinates: x, y Data variables: - temperature (x, y, time) float64 29.11 18.2 22.83 ... 18.28 16.15 26.63 - precipitation (x, y, time) float64 5.68 9.256 0.7104 ... 7.992 4.615 7.805 + temperature (x, y, time) float64 96B 29.11 18.2 22.83 ... 16.15 26.63 + precipitation (x, y, time) float64 96B 5.68 9.256 0.7104 ... 4.615 7.805 Attributes: description: Weather related data. @@ -632,16 +632,16 @@ class Dataset( other variables had: >>> ds.isel(ds.temperature.argmin(...)) - + Size: 48B Dimensions: () Coordinates: - lon float64 -99.32 - lat float64 42.21 - time datetime64[ns] 2014-09-08 - reference_time datetime64[ns] 2014-09-05 + lon float64 8B -99.32 + lat float64 8B 42.21 + time datetime64[ns] 8B 2014-09-08 + reference_time datetime64[ns] 8B 2014-09-05 Data variables: - temperature float64 7.182 - precipitation float64 8.326 + temperature float64 8B 7.182 + precipitation float64 8B 8.326 Attributes: description: Weather related data. @@ -1271,60 +1271,60 @@ def copy(self, deep: bool = False, data: DataVars | None = None) -> Self: ... coords={"x": ["one", "two"]}, ... ) >>> ds.copy() - + Size: 88B Dimensions: (dim_0: 2, dim_1: 3, x: 2) Coordinates: - * x (x) >> ds_0 = ds.copy(deep=False) >>> ds_0["foo"][0, 0] = 7 >>> ds_0 - + Size: 88B Dimensions: (dim_0: 2, dim_1: 3, x: 2) Coordinates: - * x (x) >> ds - + Size: 88B Dimensions: (dim_0: 2, dim_1: 3, x: 2) Coordinates: - * x (x) >> ds.copy(data={"foo": np.arange(6).reshape(2, 3), "bar": ["a", "b"]}) - + Size: 80B Dimensions: (dim_0: 2, dim_1: 3, x: 2) Coordinates: - * x (x) >> ds - + Size: 88B Dimensions: (dim_0: 2, dim_1: 3, x: 2) Coordinates: - * x (x) bool: ... coords={"space": [0], "time": [0, 1, 2]}, ... ) >>> a - + Size: 56B Dimensions: (space: 1, time: 3) Coordinates: - * space (space) int64 0 - * time (time) int64 0 1 2 + * space (space) int64 8B 0 + * time (time) int64 24B 0 1 2 Data variables: - variable_name (space, time) int64 1 2 3 + variable_name (space, time) int64 24B 1 2 3 # 2D array with shape (3, 1) @@ -1750,13 +1750,13 @@ def broadcast_equals(self, other: Self) -> bool: ... coords={"time": [0, 1, 2], "space": [0]}, ... ) >>> b - + Size: 56B Dimensions: (time: 3, space: 1) Coordinates: - * time (time) int64 0 1 2 - * space (space) int64 0 + * time (time) int64 24B 0 1 2 + * space (space) int64 8B 0 Data variables: - variable_name (time, space) int64 1 2 3 + variable_name (time, space) int64 24B 1 2 3 .equals returns True if two Datasets have the same values, dimensions, and coordinates. .broadcast_equals returns True if the results of broadcasting two Datasets against each other have the same values, dimensions, and coordinates. @@ -1803,13 +1803,13 @@ def equals(self, other: Self) -> bool: ... coords={"space": [0], "time": [0, 1, 2]}, ... ) >>> dataset1 - + Size: 56B Dimensions: (space: 1, time: 3) Coordinates: - * space (space) int64 0 - * time (time) int64 0 1 2 + * space (space) int64 8B 0 + * time (time) int64 24B 0 1 2 Data variables: - variable_name (space, time) int64 1 2 3 + variable_name (space, time) int64 24B 1 2 3 # 2D array with shape (3, 1) @@ -1819,13 +1819,13 @@ def equals(self, other: Self) -> bool: ... coords={"time": [0, 1, 2], "space": [0]}, ... ) >>> dataset2 - + Size: 56B Dimensions: (time: 3, space: 1) Coordinates: - * time (time) int64 0 1 2 - * space (space) int64 0 + * time (time) int64 24B 0 1 2 + * space (space) int64 8B 0 Data variables: - variable_name (time, space) int64 1 2 3 + variable_name (time, space) int64 24B 1 2 3 >>> dataset1.equals(dataset2) False @@ -1886,32 +1886,32 @@ def identical(self, other: Self) -> bool: ... attrs={"units": "ft"}, ... ) >>> a - + Size: 48B Dimensions: (X: 3) Coordinates: - * X (X) int64 1 2 3 + * X (X) int64 24B 1 2 3 Data variables: - Width (X) int64 1 2 3 + Width (X) int64 24B 1 2 3 Attributes: units: m >>> b - + Size: 48B Dimensions: (X: 3) Coordinates: - * X (X) int64 1 2 3 + * X (X) int64 24B 1 2 3 Data variables: - Width (X) int64 1 2 3 + Width (X) int64 24B 1 2 3 Attributes: units: m >>> c - + Size: 48B Dimensions: (X: 3) Coordinates: - * X (X) int64 1 2 3 + * X (X) int64 24B 1 2 3 Data variables: - Width (X) int64 1 2 3 + Width (X) int64 24B 1 2 3 Attributes: units: ft @@ -1993,19 +1993,19 @@ def set_coords(self, names: Hashable | Iterable[Hashable]) -> Self: ... } ... ) >>> dataset - + Size: 48B Dimensions: (time: 3) Coordinates: - * time (time) datetime64[ns] 2023-01-01 2023-01-02 2023-01-03 + * time (time) datetime64[ns] 24B 2023-01-01 2023-01-02 2023-01-03 Data variables: - pressure (time) float64 1.013 1.2 3.5 + pressure (time) float64 24B 1.013 1.2 3.5 >>> dataset.set_coords("pressure") - + Size: 48B Dimensions: (time: 3) Coordinates: - pressure (time) float64 1.013 1.2 3.5 - * time (time) datetime64[ns] 2023-01-01 2023-01-02 2023-01-03 + pressure (time) float64 24B 1.013 1.2 3.5 + * time (time) datetime64[ns] 24B 2023-01-01 2023-01-02 2023-01-03 Data variables: *empty* @@ -2073,16 +2073,16 @@ def reset_coords( # Dataset before resetting coordinates >>> dataset - + Size: 184B Dimensions: (time: 2, lat: 2, lon: 2) Coordinates: - * time (time) datetime64[ns] 2023-01-01 2023-01-02 - * lat (lat) int64 40 41 - * lon (lon) int64 -80 -79 - altitude int64 1000 + * time (time) datetime64[ns] 16B 2023-01-01 2023-01-02 + * lat (lat) int64 16B 40 41 + * lon (lon) int64 16B -80 -79 + altitude int64 8B 1000 Data variables: - temperature (time, lat, lon) int64 25 26 27 28 29 30 31 32 - precipitation (time, lat, lon) float64 0.5 0.8 0.2 0.4 0.3 0.6 0.7 0.9 + temperature (time, lat, lon) int64 64B 25 26 27 28 29 30 31 32 + precipitation (time, lat, lon) float64 64B 0.5 0.8 0.2 0.4 0.3 0.6 0.7 0.9 # Reset the 'altitude' coordinate @@ -2091,16 +2091,16 @@ def reset_coords( # Dataset after resetting coordinates >>> dataset_reset - + Size: 184B Dimensions: (time: 2, lat: 2, lon: 2) Coordinates: - * time (time) datetime64[ns] 2023-01-01 2023-01-02 - * lat (lat) int64 40 41 - * lon (lon) int64 -80 -79 + * time (time) datetime64[ns] 16B 2023-01-01 2023-01-02 + * lat (lat) int64 16B 40 41 + * lon (lon) int64 16B -80 -79 Data variables: - temperature (time, lat, lon) int64 25 26 27 28 29 30 31 32 - precipitation (time, lat, lon) float64 0.5 0.8 0.2 0.4 0.3 0.6 0.7 0.9 - altitude int64 1000 + temperature (time, lat, lon) int64 64B 25 26 27 28 29 30 31 32 + precipitation (time, lat, lon) float64 64B 0.5 0.8 0.2 0.4 0.3 0.6 0.7 0.9 + altitude int64 8B 1000 Returns ------- @@ -2893,39 +2893,39 @@ def isel( # A specific element from the dataset is selected >>> dataset.isel(student=1, test=0) - + Size: 68B Dimensions: () Coordinates: - student >> slice_of_data = dataset.isel(student=slice(0, 2), test=slice(0, 2)) >>> slice_of_data - + Size: 168B Dimensions: (student: 2, test: 2) Coordinates: - * student (student) >> index_array = xr.DataArray([0, 2], dims="student") >>> indexed_data = dataset.isel(student=index_array) >>> indexed_data - + Size: 224B Dimensions: (student: 2, test: 3) Coordinates: - * student (student) >> busiest_days = dataset.sortby("pageviews", ascending=False) >>> busiest_days.head() - + Size: 120B Dimensions: (date: 5) Coordinates: - * date (date) datetime64[ns] 2023-01-05 2023-01-04 ... 2023-01-03 + * date (date) datetime64[ns] 40B 2023-01-05 2023-01-04 ... 2023-01-03 Data variables: - pageviews (date) int64 2000 1800 1500 1200 900 - visitors (date) int64 1500 1200 1000 800 600 + pageviews (date) int64 40B 2000 1800 1500 1200 900 + visitors (date) int64 40B 1500 1200 1000 800 600 # Retrieve the 3 most busiest days in terms of pageviews >>> busiest_days.head(3) - + Size: 72B Dimensions: (date: 3) Coordinates: - * date (date) datetime64[ns] 2023-01-05 2023-01-04 2023-01-02 + * date (date) datetime64[ns] 24B 2023-01-05 2023-01-04 2023-01-02 Data variables: - pageviews (date) int64 2000 1800 1500 - visitors (date) int64 1500 1200 1000 + pageviews (date) int64 24B 2000 1800 1500 + visitors (date) int64 24B 1500 1200 1000 # Using a dictionary to specify the number of elements for specific dimensions >>> busiest_days.head({"date": 3}) - + Size: 72B Dimensions: (date: 3) Coordinates: - * date (date) datetime64[ns] 2023-01-05 2023-01-04 2023-01-02 + * date (date) datetime64[ns] 24B 2023-01-05 2023-01-04 2023-01-02 Data variables: - pageviews (date) int64 2000 1800 1500 - visitors (date) int64 1500 1200 1000 + pageviews (date) int64 24B 2000 1800 1500 + visitors (date) int64 24B 1500 1200 1000 See Also -------- @@ -3233,33 +3233,33 @@ def tail( ... ) >>> sorted_dataset = dataset.sortby("energy_expenditure", ascending=False) >>> sorted_dataset - + Size: 240B Dimensions: (activity: 5) Coordinates: - * activity (activity) >> sorted_dataset.tail(3) - + Size: 144B Dimensions: (activity: 3) Coordinates: - * activity (activity) >> sorted_dataset.tail({"activity": 3}) - + Size: 144B Dimensions: (activity: 3) Coordinates: - * activity (activity) >> x_ds = xr.Dataset({"foo": x}) >>> x_ds - + Size: 328B Dimensions: (x: 2, y: 13) Coordinates: - * x (x) int64 0 1 - * y (y) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 + * x (x) int64 16B 0 1 + * y (y) int64 104B 0 1 2 3 4 5 6 7 8 9 10 11 12 Data variables: - foo (x, y) int64 0 1 2 3 4 5 6 7 8 9 ... 16 17 18 19 20 21 22 23 24 25 + foo (x, y) int64 208B 0 1 2 3 4 5 6 7 8 ... 17 18 19 20 21 22 23 24 25 >>> x_ds.thin(3) - + Size: 88B Dimensions: (x: 1, y: 5) Coordinates: - * x (x) int64 0 - * y (y) int64 0 3 6 9 12 + * x (x) int64 8B 0 + * y (y) int64 40B 0 3 6 9 12 Data variables: - foo (x, y) int64 0 3 6 9 12 + foo (x, y) int64 40B 0 3 6 9 12 >>> x.thin({"x": 2, "y": 5}) - + Size: 24B array([[ 0, 5, 10]]) Coordinates: - * x (x) int64 0 - * y (y) int64 0 5 10 + * x (x) int64 8B 0 + * y (y) int64 24B 0 5 10 See Also -------- @@ -3608,13 +3608,13 @@ def reindex( ... coords={"station": ["boston", "nyc", "seattle", "denver"]}, ... ) >>> x - + Size: 176B Dimensions: (station: 4) Coordinates: - * station (station) >> x.indexes Indexes: station Index(['boston', 'nyc', 'seattle', 'denver'], dtype='object', name='station') @@ -3624,37 +3624,37 @@ def reindex( >>> new_index = ["boston", "austin", "seattle", "lincoln"] >>> x.reindex({"station": new_index}) - + Size: 176B Dimensions: (station: 4) Coordinates: - * station (station) >> x.reindex({"station": new_index}, fill_value=0) - + Size: 176B Dimensions: (station: 4) Coordinates: - * station (station) >> x.reindex( ... {"station": new_index}, fill_value={"temperature": 0, "pressure": 100} ... ) - + Size: 176B Dimensions: (station: 4) Coordinates: - * station (station) >> x2 - + Size: 144B Dimensions: (time: 6) Coordinates: - * time (time) datetime64[ns] 2019-01-01 2019-01-02 ... 2019-01-06 + * time (time) datetime64[ns] 48B 2019-01-01 2019-01-02 ... 2019-01-06 Data variables: - temperature (time) float64 15.57 12.77 nan 0.3081 16.59 15.12 - pressure (time) float64 481.8 191.7 395.9 264.4 284.0 462.8 + temperature (time) float64 48B 15.57 12.77 nan 0.3081 16.59 15.12 + pressure (time) float64 48B 481.8 191.7 395.9 264.4 284.0 462.8 Suppose we decide to expand the dataset to cover a wider date range. >>> time_index2 = pd.date_range("12/29/2018", periods=10, freq="D") >>> x2.reindex({"time": time_index2}) - + Size: 240B Dimensions: (time: 10) Coordinates: - * time (time) datetime64[ns] 2018-12-29 2018-12-30 ... 2019-01-07 + * time (time) datetime64[ns] 80B 2018-12-29 2018-12-30 ... 2019-01-07 Data variables: - temperature (time) float64 nan nan nan 15.57 ... 0.3081 16.59 15.12 nan - pressure (time) float64 nan nan nan 481.8 ... 264.4 284.0 462.8 nan + temperature (time) float64 80B nan nan nan 15.57 ... 0.3081 16.59 15.12 nan + pressure (time) float64 80B nan nan nan 481.8 ... 264.4 284.0 462.8 nan The index entries that did not have a value in the original data frame (for example, `2018-12-29`) are by default filled with NaN. If desired, we can fill in the missing values using one of several options. @@ -3707,33 +3707,33 @@ def reindex( >>> x3 = x2.reindex({"time": time_index2}, method="bfill") >>> x3 - + Size: 240B Dimensions: (time: 10) Coordinates: - * time (time) datetime64[ns] 2018-12-29 2018-12-30 ... 2019-01-07 + * time (time) datetime64[ns] 80B 2018-12-29 2018-12-30 ... 2019-01-07 Data variables: - temperature (time) float64 15.57 15.57 15.57 15.57 ... 16.59 15.12 nan - pressure (time) float64 481.8 481.8 481.8 481.8 ... 284.0 462.8 nan + temperature (time) float64 80B 15.57 15.57 15.57 15.57 ... 16.59 15.12 nan + pressure (time) float64 80B 481.8 481.8 481.8 481.8 ... 284.0 462.8 nan Please note that the `NaN` value present in the original dataset (at index value `2019-01-03`) will not be filled by any of the value propagation schemes. >>> x2.where(x2.temperature.isnull(), drop=True) - + Size: 24B Dimensions: (time: 1) Coordinates: - * time (time) datetime64[ns] 2019-01-03 + * time (time) datetime64[ns] 8B 2019-01-03 Data variables: - temperature (time) float64 nan - pressure (time) float64 395.9 + temperature (time) float64 8B nan + pressure (time) float64 8B 395.9 >>> x3.where(x3.temperature.isnull(), drop=True) - + Size: 48B Dimensions: (time: 2) Coordinates: - * time (time) datetime64[ns] 2019-01-03 2019-01-07 + * time (time) datetime64[ns] 16B 2019-01-03 2019-01-07 Data variables: - temperature (time) float64 nan nan - pressure (time) float64 395.9 nan + temperature (time) float64 16B nan nan + pressure (time) float64 16B 395.9 nan This is because filling while reindexing does not look at dataset values, but only compares the original and desired indexes. If you do want to fill in the `NaN` values present in the @@ -3860,38 +3860,38 @@ def interp( ... coords={"x": [0, 1, 2], "y": [10, 12, 14, 16]}, ... ) >>> ds - + Size: 176B Dimensions: (x: 3, y: 4) Coordinates: - * x (x) int64 0 1 2 - * y (y) int64 10 12 14 16 + * x (x) int64 24B 0 1 2 + * y (y) int64 32B 10 12 14 16 Data variables: - a (x) int64 5 7 4 - b (x, y) float64 1.0 4.0 2.0 9.0 2.0 7.0 6.0 nan 6.0 nan 5.0 8.0 + a (x) int64 24B 5 7 4 + b (x, y) float64 96B 1.0 4.0 2.0 9.0 2.0 7.0 6.0 nan 6.0 nan 5.0 8.0 1D interpolation with the default method (linear): >>> ds.interp(x=[0, 0.75, 1.25, 1.75]) - + Size: 224B Dimensions: (x: 4, y: 4) Coordinates: - * y (y) int64 10 12 14 16 - * x (x) float64 0.0 0.75 1.25 1.75 + * y (y) int64 32B 10 12 14 16 + * x (x) float64 32B 0.0 0.75 1.25 1.75 Data variables: - a (x) float64 5.0 6.5 6.25 4.75 - b (x, y) float64 1.0 4.0 2.0 nan 1.75 6.25 ... nan 5.0 nan 5.25 nan + a (x) float64 32B 5.0 6.5 6.25 4.75 + b (x, y) float64 128B 1.0 4.0 2.0 nan 1.75 ... nan 5.0 nan 5.25 nan 1D interpolation with a different method: >>> ds.interp(x=[0, 0.75, 1.25, 1.75], method="nearest") - + Size: 224B Dimensions: (x: 4, y: 4) Coordinates: - * y (y) int64 10 12 14 16 - * x (x) float64 0.0 0.75 1.25 1.75 + * y (y) int64 32B 10 12 14 16 + * x (x) float64 32B 0.0 0.75 1.25 1.75 Data variables: - a (x) float64 5.0 7.0 7.0 4.0 - b (x, y) float64 1.0 4.0 2.0 9.0 2.0 7.0 ... 6.0 nan 6.0 nan 5.0 8.0 + a (x) float64 32B 5.0 7.0 7.0 4.0 + b (x, y) float64 128B 1.0 4.0 2.0 9.0 2.0 7.0 ... nan 6.0 nan 5.0 8.0 1D extrapolation: @@ -3900,26 +3900,26 @@ def interp( ... method="linear", ... kwargs={"fill_value": "extrapolate"}, ... ) - + Size: 224B Dimensions: (x: 4, y: 4) Coordinates: - * y (y) int64 10 12 14 16 - * x (x) float64 1.0 1.5 2.5 3.5 + * y (y) int64 32B 10 12 14 16 + * x (x) float64 32B 1.0 1.5 2.5 3.5 Data variables: - a (x) float64 7.0 5.5 2.5 -0.5 - b (x, y) float64 2.0 7.0 6.0 nan 4.0 nan ... 4.5 nan 12.0 nan 3.5 nan + a (x) float64 32B 7.0 5.5 2.5 -0.5 + b (x, y) float64 128B 2.0 7.0 6.0 nan 4.0 ... nan 12.0 nan 3.5 nan 2D interpolation: >>> ds.interp(x=[0, 0.75, 1.25, 1.75], y=[11, 13, 15], method="linear") - + Size: 184B Dimensions: (x: 4, y: 3) Coordinates: - * x (x) float64 0.0 0.75 1.25 1.75 - * y (y) int64 11 13 15 + * x (x) float64 32B 0.0 0.75 1.25 1.75 + * y (y) int64 24B 11 13 15 Data variables: - a (x) float64 5.0 6.5 6.25 4.75 - b (x, y) float64 2.5 3.0 nan 4.0 5.625 nan nan nan nan nan nan nan + a (x) float64 32B 5.0 6.5 6.25 4.75 + b (x, y) float64 96B 2.5 3.0 nan 4.0 5.625 ... nan nan nan nan nan """ from xarray.core import missing @@ -4400,35 +4400,35 @@ def swap_dims( ... coords={"x": ["a", "b"], "y": ("x", [0, 1])}, ... ) >>> ds - + Size: 56B Dimensions: (x: 2) Coordinates: - * x (x) >> ds.swap_dims({"x": "y"}) - + Size: 56B Dimensions: (y: 2) Coordinates: - x (y) >> ds.swap_dims({"x": "z"}) - + Size: 56B Dimensions: (z: 2) Coordinates: - x (z) >> dataset = xr.Dataset({"temperature": ([], 25.0)}) >>> dataset - + Size: 8B Dimensions: () Data variables: - temperature float64 25.0 + temperature float64 8B 25.0 # Expand the dataset with a new dimension called "time" >>> dataset.expand_dims(dim="time") - + Size: 8B Dimensions: (time: 1) Dimensions without coordinates: time Data variables: - temperature (time) float64 25.0 + temperature (time) float64 8B 25.0 # 1D data >>> temperature_1d = xr.DataArray([25.0, 26.5, 24.8], dims="x") >>> dataset_1d = xr.Dataset({"temperature": temperature_1d}) >>> dataset_1d - + Size: 24B Dimensions: (x: 3) Dimensions without coordinates: x Data variables: - temperature (x) float64 25.0 26.5 24.8 + temperature (x) float64 24B 25.0 26.5 24.8 # Expand the dataset with a new dimension called "time" using axis argument >>> dataset_1d.expand_dims(dim="time", axis=0) - + Size: 24B Dimensions: (time: 1, x: 3) Dimensions without coordinates: time, x Data variables: - temperature (time, x) float64 25.0 26.5 24.8 + temperature (time, x) float64 24B 25.0 26.5 24.8 # 2D data >>> temperature_2d = xr.DataArray(np.random.rand(3, 4), dims=("y", "x")) >>> dataset_2d = xr.Dataset({"temperature": temperature_2d}) >>> dataset_2d - + Size: 96B Dimensions: (y: 3, x: 4) Dimensions without coordinates: y, x Data variables: - temperature (y, x) float64 0.5488 0.7152 0.6028 ... 0.3834 0.7917 0.5289 + temperature (y, x) float64 96B 0.5488 0.7152 0.6028 ... 0.7917 0.5289 # Expand the dataset with a new dimension called "time" using axis argument >>> dataset_2d.expand_dims(dim="time", axis=2) - + Size: 96B Dimensions: (y: 3, x: 4, time: 1) Dimensions without coordinates: y, x, time Data variables: - temperature (y, x, time) float64 0.5488 0.7152 0.6028 ... 0.7917 0.5289 + temperature (y, x, time) float64 96B 0.5488 0.7152 0.6028 ... 0.7917 0.5289 See Also -------- @@ -4717,22 +4717,22 @@ def set_index( ... ) >>> ds = xr.Dataset({"v": arr}) >>> ds - + Size: 104B Dimensions: (x: 2, y: 3) Coordinates: - * x (x) int64 0 1 - * y (y) int64 0 1 2 - a (x) int64 3 4 + * x (x) int64 16B 0 1 + * y (y) int64 24B 0 1 2 + a (x) int64 16B 3 4 Data variables: - v (x, y) float64 1.0 1.0 1.0 1.0 1.0 1.0 + v (x, y) float64 48B 1.0 1.0 1.0 1.0 1.0 1.0 >>> ds.set_index(x="a") - + Size: 88B Dimensions: (x: 2, y: 3) Coordinates: - * x (x) int64 3 4 - * y (y) int64 0 1 2 + * x (x) int64 16B 3 4 + * y (y) int64 24B 0 1 2 Data variables: - v (x, y) float64 1.0 1.0 1.0 1.0 1.0 1.0 + v (x, y) float64 48B 1.0 1.0 1.0 1.0 1.0 1.0 See Also -------- @@ -5333,23 +5333,23 @@ def to_stacked_array( ... ) >>> data - + Size: 76B Dimensions: (x: 2, y: 3) Coordinates: - * y (y) >> data.to_stacked_array("z", sample_dims=["x"]) - + Size: 64B array([[0, 1, 2, 6], [3, 4, 5, 7]]) Coordinates: - * z (z) object MultiIndex - * variable (z) object 'a' 'a' 'a' 'b' - * y (z) object 'u' 'v' 'w' nan + * z (z) object 32B MultiIndex + * variable (z) object 32B 'a' 'a' 'a' 'b' + * y (z) object 32B 'u' 'v' 'w' nan Dimensions without coordinates: x """ @@ -5777,66 +5777,66 @@ def drop_vars( ... }, ... ) >>> dataset - + Size: 136B Dimensions: (time: 1, latitude: 2, longitude: 2) Coordinates: - * time (time) datetime64[ns] 2023-07-01 - * latitude (latitude) float64 40.0 40.2 - * longitude (longitude) float64 -75.0 -74.8 + * time (time) datetime64[ns] 8B 2023-07-01 + * latitude (latitude) float64 16B 40.0 40.2 + * longitude (longitude) float64 16B -75.0 -74.8 Data variables: - temperature (time, latitude, longitude) float64 25.5 26.3 27.1 28.0 - humidity (time, latitude, longitude) float64 65.0 63.8 58.2 59.6 - wind_speed (time, latitude, longitude) float64 10.2 8.5 12.1 9.8 + temperature (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0 + humidity (time, latitude, longitude) float64 32B 65.0 63.8 58.2 59.6 + wind_speed (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8 Drop the 'humidity' variable >>> dataset.drop_vars(["humidity"]) - + Size: 104B Dimensions: (time: 1, latitude: 2, longitude: 2) Coordinates: - * time (time) datetime64[ns] 2023-07-01 - * latitude (latitude) float64 40.0 40.2 - * longitude (longitude) float64 -75.0 -74.8 + * time (time) datetime64[ns] 8B 2023-07-01 + * latitude (latitude) float64 16B 40.0 40.2 + * longitude (longitude) float64 16B -75.0 -74.8 Data variables: - temperature (time, latitude, longitude) float64 25.5 26.3 27.1 28.0 - wind_speed (time, latitude, longitude) float64 10.2 8.5 12.1 9.8 + temperature (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0 + wind_speed (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8 Drop the 'humidity', 'temperature' variables >>> dataset.drop_vars(["humidity", "temperature"]) - + Size: 72B Dimensions: (time: 1, latitude: 2, longitude: 2) Coordinates: - * time (time) datetime64[ns] 2023-07-01 - * latitude (latitude) float64 40.0 40.2 - * longitude (longitude) float64 -75.0 -74.8 + * time (time) datetime64[ns] 8B 2023-07-01 + * latitude (latitude) float64 16B 40.0 40.2 + * longitude (longitude) float64 16B -75.0 -74.8 Data variables: - wind_speed (time, latitude, longitude) float64 10.2 8.5 12.1 9.8 + wind_speed (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8 Drop all indexes >>> dataset.drop_vars(lambda x: x.indexes) - + Size: 96B Dimensions: (time: 1, latitude: 2, longitude: 2) Dimensions without coordinates: time, latitude, longitude Data variables: - temperature (time, latitude, longitude) float64 25.5 26.3 27.1 28.0 - humidity (time, latitude, longitude) float64 65.0 63.8 58.2 59.6 - wind_speed (time, latitude, longitude) float64 10.2 8.5 12.1 9.8 + temperature (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0 + humidity (time, latitude, longitude) float64 32B 65.0 63.8 58.2 59.6 + wind_speed (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8 Attempt to drop non-existent variable with errors="ignore" >>> dataset.drop_vars(["pressure"], errors="ignore") - + Size: 136B Dimensions: (time: 1, latitude: 2, longitude: 2) Coordinates: - * time (time) datetime64[ns] 2023-07-01 - * latitude (latitude) float64 40.0 40.2 - * longitude (longitude) float64 -75.0 -74.8 + * time (time) datetime64[ns] 8B 2023-07-01 + * latitude (latitude) float64 16B 40.0 40.2 + * longitude (longitude) float64 16B -75.0 -74.8 Data variables: - temperature (time, latitude, longitude) float64 25.5 26.3 27.1 28.0 - humidity (time, latitude, longitude) float64 65.0 63.8 58.2 59.6 - wind_speed (time, latitude, longitude) float64 10.2 8.5 12.1 9.8 + temperature (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0 + humidity (time, latitude, longitude) float64 32B 65.0 63.8 58.2 59.6 + wind_speed (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8 Attempt to drop non-existent variable with errors="raise" @@ -6033,29 +6033,29 @@ def drop_sel( >>> labels = ["a", "b", "c"] >>> ds = xr.Dataset({"A": (["x", "y"], data), "y": labels}) >>> ds - + Size: 60B Dimensions: (x: 2, y: 3) Coordinates: - * y (y) >> ds.drop_sel(y=["a", "c"]) - + Size: 20B Dimensions: (x: 2, y: 1) Coordinates: - * y (y) >> ds.drop_sel(y="b") - + Size: 40B Dimensions: (x: 2, y: 2) Coordinates: - * y (y) Self: >>> labels = ["a", "b", "c"] >>> ds = xr.Dataset({"A": (["x", "y"], data), "y": labels}) >>> ds - + Size: 60B Dimensions: (x: 2, y: 3) Coordinates: - * y (y) >> ds.drop_isel(y=[0, 2]) - + Size: 20B Dimensions: (x: 2, y: 1) Coordinates: - * y (y) >> ds.drop_isel(y=1) - + Size: 40B Dimensions: (x: 2, y: 2) Coordinates: - * y (y) >> dataset - + Size: 104B Dimensions: (time: 4, location: 2) Coordinates: - * time (time) int64 1 2 3 4 - * location (location) >> dataset.dropna(dim="time") - + Size: 80B Dimensions: (time: 3, location: 2) Coordinates: - * time (time) int64 1 3 4 - * location (location) >> dataset.dropna(dim="time", how="any") - + Size: 80B Dimensions: (time: 3, location: 2) Coordinates: - * time (time) int64 1 3 4 - * location (location) >> dataset.dropna(dim="time", how="all") - + Size: 104B Dimensions: (time: 4, location: 2) Coordinates: - * time (time) int64 1 2 3 4 - * location (location) >> dataset.dropna(dim="time", thresh=2) - + Size: 80B Dimensions: (time: 3, location: 2) Coordinates: - * time (time) int64 1 3 4 - * location (location) Self: ... coords={"x": [0, 1, 2, 3]}, ... ) >>> ds - + Size: 160B Dimensions: (x: 4) Coordinates: - * x (x) int64 0 1 2 3 + * x (x) int64 32B 0 1 2 3 Data variables: - A (x) float64 nan 2.0 nan 0.0 - B (x) float64 3.0 4.0 nan 1.0 - C (x) float64 nan nan nan 5.0 - D (x) float64 nan 3.0 nan 4.0 + A (x) float64 32B nan 2.0 nan 0.0 + B (x) float64 32B 3.0 4.0 nan 1.0 + C (x) float64 32B nan nan nan 5.0 + D (x) float64 32B nan 3.0 nan 4.0 Replace all `NaN` values with 0s. >>> ds.fillna(0) - + Size: 160B Dimensions: (x: 4) Coordinates: - * x (x) int64 0 1 2 3 + * x (x) int64 32B 0 1 2 3 Data variables: - A (x) float64 0.0 2.0 0.0 0.0 - B (x) float64 3.0 4.0 0.0 1.0 - C (x) float64 0.0 0.0 0.0 5.0 - D (x) float64 0.0 3.0 0.0 4.0 + A (x) float64 32B 0.0 2.0 0.0 0.0 + B (x) float64 32B 3.0 4.0 0.0 1.0 + C (x) float64 32B 0.0 0.0 0.0 5.0 + D (x) float64 32B 0.0 3.0 0.0 4.0 Replace all `NaN` elements in column ‘A’, ‘B’, ‘C’, and ‘D’, with 0, 1, 2, and 3 respectively. >>> values = {"A": 0, "B": 1, "C": 2, "D": 3} >>> ds.fillna(value=values) - + Size: 160B Dimensions: (x: 4) Coordinates: - * x (x) int64 0 1 2 3 + * x (x) int64 32B 0 1 2 3 Data variables: - A (x) float64 0.0 2.0 0.0 0.0 - B (x) float64 3.0 4.0 1.0 1.0 - C (x) float64 2.0 2.0 2.0 5.0 - D (x) float64 3.0 3.0 3.0 4.0 + A (x) float64 32B 0.0 2.0 0.0 0.0 + B (x) float64 32B 3.0 4.0 1.0 1.0 + C (x) float64 32B 2.0 2.0 2.0 5.0 + D (x) float64 32B 3.0 3.0 3.0 4.0 """ if utils.is_dict_like(value): value_keys = getattr(value, "data_vars", value).keys() @@ -6543,37 +6543,37 @@ def interpolate_na( ... coords={"x": [0, 1, 2, 3, 4]}, ... ) >>> ds - + Size: 200B Dimensions: (x: 5) Coordinates: - * x (x) int64 0 1 2 3 4 + * x (x) int64 40B 0 1 2 3 4 Data variables: - A (x) float64 nan 2.0 3.0 nan 0.0 - B (x) float64 3.0 4.0 nan 1.0 7.0 - C (x) float64 nan nan nan 5.0 0.0 - D (x) float64 nan 3.0 nan -1.0 4.0 + A (x) float64 40B nan 2.0 3.0 nan 0.0 + B (x) float64 40B 3.0 4.0 nan 1.0 7.0 + C (x) float64 40B nan nan nan 5.0 0.0 + D (x) float64 40B nan 3.0 nan -1.0 4.0 >>> ds.interpolate_na(dim="x", method="linear") - + Size: 200B Dimensions: (x: 5) Coordinates: - * x (x) int64 0 1 2 3 4 + * x (x) int64 40B 0 1 2 3 4 Data variables: - A (x) float64 nan 2.0 3.0 1.5 0.0 - B (x) float64 3.0 4.0 2.5 1.0 7.0 - C (x) float64 nan nan nan 5.0 0.0 - D (x) float64 nan 3.0 1.0 -1.0 4.0 + A (x) float64 40B nan 2.0 3.0 1.5 0.0 + B (x) float64 40B 3.0 4.0 2.5 1.0 7.0 + C (x) float64 40B nan nan nan 5.0 0.0 + D (x) float64 40B nan 3.0 1.0 -1.0 4.0 >>> ds.interpolate_na(dim="x", method="linear", fill_value="extrapolate") - + Size: 200B Dimensions: (x: 5) Coordinates: - * x (x) int64 0 1 2 3 4 + * x (x) int64 40B 0 1 2 3 4 Data variables: - A (x) float64 1.0 2.0 3.0 1.5 0.0 - B (x) float64 3.0 4.0 2.5 1.0 7.0 - C (x) float64 20.0 15.0 10.0 5.0 0.0 - D (x) float64 5.0 3.0 1.0 -1.0 4.0 + A (x) float64 40B 1.0 2.0 3.0 1.5 0.0 + B (x) float64 40B 3.0 4.0 2.5 1.0 7.0 + C (x) float64 40B 20.0 15.0 10.0 5.0 0.0 + D (x) float64 40B 5.0 3.0 1.0 -1.0 4.0 """ from xarray.core.missing import _apply_over_vars_with_dim, interp_na @@ -6613,32 +6613,32 @@ def ffill(self, dim: Hashable, limit: int | None = None) -> Self: ... ) >>> dataset = xr.Dataset({"data": (("time",), data)}, coords={"time": time}) >>> dataset - + Size: 160B Dimensions: (time: 10) Coordinates: - * time (time) datetime64[ns] 2023-01-01 2023-01-02 ... 2023-01-10 + * time (time) datetime64[ns] 80B 2023-01-01 2023-01-02 ... 2023-01-10 Data variables: - data (time) float64 1.0 nan nan nan 5.0 nan nan 8.0 nan 10.0 + data (time) float64 80B 1.0 nan nan nan 5.0 nan nan 8.0 nan 10.0 # Perform forward fill (ffill) on the dataset >>> dataset.ffill(dim="time") - + Size: 160B Dimensions: (time: 10) Coordinates: - * time (time) datetime64[ns] 2023-01-01 2023-01-02 ... 2023-01-10 + * time (time) datetime64[ns] 80B 2023-01-01 2023-01-02 ... 2023-01-10 Data variables: - data (time) float64 1.0 1.0 1.0 1.0 5.0 5.0 5.0 8.0 8.0 10.0 + data (time) float64 80B 1.0 1.0 1.0 1.0 5.0 5.0 5.0 8.0 8.0 10.0 # Limit the forward filling to a maximum of 2 consecutive NaN values >>> dataset.ffill(dim="time", limit=2) - + Size: 160B Dimensions: (time: 10) Coordinates: - * time (time) datetime64[ns] 2023-01-01 2023-01-02 ... 2023-01-10 + * time (time) datetime64[ns] 80B 2023-01-01 2023-01-02 ... 2023-01-10 Data variables: - data (time) float64 1.0 1.0 1.0 nan 5.0 5.0 5.0 8.0 8.0 10.0 + data (time) float64 80B 1.0 1.0 1.0 nan 5.0 5.0 5.0 8.0 8.0 10.0 Returns ------- @@ -6678,32 +6678,32 @@ def bfill(self, dim: Hashable, limit: int | None = None) -> Self: ... ) >>> dataset = xr.Dataset({"data": (("time",), data)}, coords={"time": time}) >>> dataset - + Size: 160B Dimensions: (time: 10) Coordinates: - * time (time) datetime64[ns] 2023-01-01 2023-01-02 ... 2023-01-10 + * time (time) datetime64[ns] 80B 2023-01-01 2023-01-02 ... 2023-01-10 Data variables: - data (time) float64 1.0 nan nan nan 5.0 nan nan 8.0 nan 10.0 + data (time) float64 80B 1.0 nan nan nan 5.0 nan nan 8.0 nan 10.0 # filled dataset, fills NaN values by propagating values backward >>> dataset.bfill(dim="time") - + Size: 160B Dimensions: (time: 10) Coordinates: - * time (time) datetime64[ns] 2023-01-01 2023-01-02 ... 2023-01-10 + * time (time) datetime64[ns] 80B 2023-01-01 2023-01-02 ... 2023-01-10 Data variables: - data (time) float64 1.0 5.0 5.0 5.0 5.0 8.0 8.0 8.0 10.0 10.0 + data (time) float64 80B 1.0 5.0 5.0 5.0 5.0 8.0 8.0 8.0 10.0 10.0 # Limit the backward filling to a maximum of 2 consecutive NaN values >>> dataset.bfill(dim="time", limit=2) - + Size: 160B Dimensions: (time: 10) Coordinates: - * time (time) datetime64[ns] 2023-01-01 2023-01-02 ... 2023-01-10 + * time (time) datetime64[ns] 80B 2023-01-01 2023-01-02 ... 2023-01-10 Data variables: - data (time) float64 1.0 nan 5.0 5.0 5.0 8.0 8.0 8.0 10.0 10.0 + data (time) float64 80B 1.0 nan 5.0 5.0 5.0 8.0 8.0 8.0 10.0 10.0 Returns ------- @@ -6801,13 +6801,13 @@ def reduce( >>> percentile_scores = dataset.reduce(np.percentile, q=75, dim="test") >>> percentile_scores - + Size: 132B Dimensions: (student: 3) Coordinates: - * student (student) >> da = xr.DataArray(np.random.randn(2, 3)) >>> ds = xr.Dataset({"foo": da, "bar": ("x", [-1, 2])}) >>> ds - + Size: 64B Dimensions: (dim_0: 2, dim_1: 3, x: 2) Dimensions without coordinates: dim_0, dim_1, x Data variables: - foo (dim_0, dim_1) float64 1.764 0.4002 0.9787 2.241 1.868 -0.9773 - bar (x) int64 -1 2 + foo (dim_0, dim_1) float64 48B 1.764 0.4002 0.9787 2.241 1.868 -0.9773 + bar (x) int64 16B -1 2 >>> ds.map(np.fabs) - + Size: 64B Dimensions: (dim_0: 2, dim_1: 3, x: 2) Dimensions without coordinates: dim_0, dim_1, x Data variables: - foo (dim_0, dim_1) float64 1.764 0.4002 0.9787 2.241 1.868 0.9773 - bar (x) float64 1.0 2.0 + foo (dim_0, dim_1) float64 48B 1.764 0.4002 0.9787 2.241 1.868 0.9773 + bar (x) float64 16B 1.0 2.0 """ if keep_attrs is None: keep_attrs = _get_keep_attrs(default=False) @@ -7005,40 +7005,40 @@ def assign( ... coords={"lat": [10, 20], "lon": [150, 160]}, ... ) >>> x - + Size: 96B Dimensions: (lat: 2, lon: 2) Coordinates: - * lat (lat) int64 10 20 - * lon (lon) int64 150 160 + * lat (lat) int64 16B 10 20 + * lon (lon) int64 16B 150 160 Data variables: - temperature_c (lat, lon) float64 10.98 14.3 12.06 10.9 - precipitation (lat, lon) float64 0.4237 0.6459 0.4376 0.8918 + temperature_c (lat, lon) float64 32B 10.98 14.3 12.06 10.9 + precipitation (lat, lon) float64 32B 0.4237 0.6459 0.4376 0.8918 Where the value is a callable, evaluated on dataset: >>> x.assign(temperature_f=lambda x: x.temperature_c * 9 / 5 + 32) - + Size: 128B Dimensions: (lat: 2, lon: 2) Coordinates: - * lat (lat) int64 10 20 - * lon (lon) int64 150 160 + * lat (lat) int64 16B 10 20 + * lon (lon) int64 16B 150 160 Data variables: - temperature_c (lat, lon) float64 10.98 14.3 12.06 10.9 - precipitation (lat, lon) float64 0.4237 0.6459 0.4376 0.8918 - temperature_f (lat, lon) float64 51.76 57.75 53.7 51.62 + temperature_c (lat, lon) float64 32B 10.98 14.3 12.06 10.9 + precipitation (lat, lon) float64 32B 0.4237 0.6459 0.4376 0.8918 + temperature_f (lat, lon) float64 32B 51.76 57.75 53.7 51.62 Alternatively, the same behavior can be achieved by directly referencing an existing dataarray: >>> x.assign(temperature_f=x["temperature_c"] * 9 / 5 + 32) - + Size: 128B Dimensions: (lat: 2, lon: 2) Coordinates: - * lat (lat) int64 10 20 - * lon (lon) int64 150 160 + * lat (lat) int64 16B 10 20 + * lon (lon) int64 16B 150 160 Data variables: - temperature_c (lat, lon) float64 10.98 14.3 12.06 10.9 - precipitation (lat, lon) float64 0.4237 0.6459 0.4376 0.8918 - temperature_f (lat, lon) float64 51.76 57.75 53.7 51.62 + temperature_c (lat, lon) float64 32B 10.98 14.3 12.06 10.9 + precipitation (lat, lon) float64 32B 0.4237 0.6459 0.4376 0.8918 + temperature_f (lat, lon) float64 32B 51.76 57.75 53.7 51.62 """ variables = either_dict_or_kwargs(variables, variables_kwargs, "assign") @@ -7508,13 +7508,13 @@ def from_dict(cls, d: Mapping[Any, Any]) -> Self: ... } >>> ds = xr.Dataset.from_dict(d) >>> ds - + Size: 60B Dimensions: (t: 3) Coordinates: - * t (t) int64 0 1 2 + * t (t) int64 24B 0 1 2 Data variables: - a (t) >> d = { ... "coords": { @@ -7529,13 +7529,13 @@ def from_dict(cls, d: Mapping[Any, Any]) -> Self: ... } >>> ds = xr.Dataset.from_dict(d) >>> ds - + Size: 60B Dimensions: (t: 3) Coordinates: - * t (t) int64 0 1 2 + * t (t) int64 24B 0 1 2 Data variables: - a (t) int64 10 20 30 - b (t) >> ds = xr.Dataset({"foo": ("x", [5, 5, 6, 6])}) >>> ds.diff("x") - + Size: 24B Dimensions: (x: 3) Dimensions without coordinates: x Data variables: - foo (x) int64 0 1 0 + foo (x) int64 24B 0 1 0 >>> ds.diff("x", 2) - + Size: 16B Dimensions: (x: 2) Dimensions without coordinates: x Data variables: - foo (x) int64 1 -1 + foo (x) int64 16B 1 -1 See Also -------- @@ -7804,11 +7804,11 @@ def shift( -------- >>> ds = xr.Dataset({"foo": ("x", list("abcde"))}) >>> ds.shift(x=2) - + Size: 40B Dimensions: (x: 5) Dimensions without coordinates: x Data variables: - foo (x) object nan nan 'a' 'b' 'c' + foo (x) object 40B nan nan 'a' 'b' 'c' """ shifts = either_dict_or_kwargs(shifts, shifts_kwargs, "shift") invalid = tuple(k for k in shifts if k not in self.dims) @@ -7873,20 +7873,20 @@ def roll( -------- >>> ds = xr.Dataset({"foo": ("x", list("abcde"))}, coords={"x": np.arange(5)}) >>> ds.roll(x=2) - + Size: 60B Dimensions: (x: 5) Coordinates: - * x (x) int64 0 1 2 3 4 + * x (x) int64 40B 0 1 2 3 4 Data variables: - foo (x) >> ds.roll(x=2, roll_coords=True) - + Size: 60B Dimensions: (x: 5) Coordinates: - * x (x) int64 3 4 0 1 2 + * x (x) int64 40B 3 4 0 1 2 Data variables: - foo (x) >> ds.sortby("x") - + Size: 88B Dimensions: (x: 2, y: 2) Coordinates: - * x (x) >> ds.sortby(lambda x: -x["y"]) - + Size: 88B Dimensions: (x: 2, y: 2) Coordinates: - * x (x) >> ds.quantile(0) # or ds.quantile(0, dim=...) - + Size: 16B Dimensions: () Coordinates: - quantile float64 0.0 + quantile float64 8B 0.0 Data variables: - a float64 0.7 + a float64 8B 0.7 >>> ds.quantile(0, dim="x") - + Size: 72B Dimensions: (y: 4) Coordinates: - * y (y) float64 1.0 1.5 2.0 2.5 - quantile float64 0.0 + * y (y) float64 32B 1.0 1.5 2.0 2.5 + quantile float64 8B 0.0 Data variables: - a (y) float64 0.7 4.2 2.6 1.5 + a (y) float64 32B 0.7 4.2 2.6 1.5 >>> ds.quantile([0, 0.5, 1]) - + Size: 48B Dimensions: (quantile: 3) Coordinates: - * quantile (quantile) float64 0.0 0.5 1.0 + * quantile (quantile) float64 24B 0.0 0.5 1.0 Data variables: - a (quantile) float64 0.7 3.4 9.4 + a (quantile) float64 24B 0.7 3.4 9.4 >>> ds.quantile([0, 0.5, 1], dim="x") - + Size: 152B Dimensions: (quantile: 3, y: 4) Coordinates: - * y (y) float64 1.0 1.5 2.0 2.5 - * quantile (quantile) float64 0.0 0.5 1.0 + * y (y) float64 32B 1.0 1.5 2.0 2.5 + * quantile (quantile) float64 24B 0.0 0.5 1.0 Data variables: - a (quantile, y) float64 0.7 4.2 2.6 1.5 3.6 ... 1.7 6.5 7.3 9.4 1.9 + a (quantile, y) float64 96B 0.7 4.2 2.6 1.5 3.6 ... 6.5 7.3 9.4 1.9 References ---------- @@ -8366,26 +8366,26 @@ def integrate( ... coords={"x": [0, 1, 2, 3], "y": ("x", [1, 7, 3, 5])}, ... ) >>> ds - + Size: 128B Dimensions: (x: 4) Coordinates: - * x (x) int64 0 1 2 3 - y (x) int64 1 7 3 5 + * x (x) int64 32B 0 1 2 3 + y (x) int64 32B 1 7 3 5 Data variables: - a (x) int64 5 5 6 6 - b (x) int64 1 2 1 0 + a (x) int64 32B 5 5 6 6 + b (x) int64 32B 1 2 1 0 >>> ds.integrate("x") - + Size: 16B Dimensions: () Data variables: - a float64 16.5 - b float64 3.5 + a float64 8B 16.5 + b float64 8B 3.5 >>> ds.integrate("y") - + Size: 16B Dimensions: () Data variables: - a float64 20.0 - b float64 4.0 + a float64 8B 20.0 + b float64 8B 4.0 """ if not isinstance(coord, (list, tuple)): coord = (coord,) @@ -8489,32 +8489,32 @@ def cumulative_integrate( ... coords={"x": [0, 1, 2, 3], "y": ("x", [1, 7, 3, 5])}, ... ) >>> ds - + Size: 128B Dimensions: (x: 4) Coordinates: - * x (x) int64 0 1 2 3 - y (x) int64 1 7 3 5 + * x (x) int64 32B 0 1 2 3 + y (x) int64 32B 1 7 3 5 Data variables: - a (x) int64 5 5 6 6 - b (x) int64 1 2 1 0 + a (x) int64 32B 5 5 6 6 + b (x) int64 32B 1 2 1 0 >>> ds.cumulative_integrate("x") - + Size: 128B Dimensions: (x: 4) Coordinates: - * x (x) int64 0 1 2 3 - y (x) int64 1 7 3 5 + * x (x) int64 32B 0 1 2 3 + y (x) int64 32B 1 7 3 5 Data variables: - a (x) float64 0.0 5.0 10.5 16.5 - b (x) float64 0.0 1.5 3.0 3.5 + a (x) float64 32B 0.0 5.0 10.5 16.5 + b (x) float64 32B 0.0 1.5 3.0 3.5 >>> ds.cumulative_integrate("y") - + Size: 128B Dimensions: (x: 4) Coordinates: - * x (x) int64 0 1 2 3 - y (x) int64 1 7 3 5 + * x (x) int64 32B 0 1 2 3 + y (x) int64 32B 1 7 3 5 Data variables: - a (x) float64 0.0 30.0 8.0 20.0 - b (x) float64 0.0 9.0 3.0 4.0 + a (x) float64 32B 0.0 30.0 8.0 20.0 + b (x) float64 32B 0.0 9.0 3.0 4.0 """ if not isinstance(coord, (list, tuple)): coord = (coord,) @@ -8602,32 +8602,32 @@ def filter_by_attrs(self, **kwargs) -> Self: Get variables matching a specific standard_name: >>> ds.filter_by_attrs(standard_name="convective_precipitation_flux") - + Size: 192B Dimensions: (x: 2, y: 2, time: 3) Coordinates: - lon (x, y) float64 -99.83 -99.32 -99.79 -99.23 - lat (x, y) float64 42.25 42.21 42.63 42.59 - * time (time) datetime64[ns] 2014-09-06 2014-09-07 2014-09-08 - reference_time datetime64[ns] 2014-09-05 + lon (x, y) float64 32B -99.83 -99.32 -99.79 -99.23 + lat (x, y) float64 32B 42.25 42.21 42.63 42.59 + * time (time) datetime64[ns] 24B 2014-09-06 2014-09-07 2014-09-08 + reference_time datetime64[ns] 8B 2014-09-05 Dimensions without coordinates: x, y Data variables: - precipitation (x, y, time) float64 5.68 9.256 0.7104 ... 7.992 4.615 7.805 + precipitation (x, y, time) float64 96B 5.68 9.256 0.7104 ... 4.615 7.805 Get all variables that have a standard_name attribute: >>> standard_name = lambda v: v is not None >>> ds.filter_by_attrs(standard_name=standard_name) - + Size: 288B Dimensions: (x: 2, y: 2, time: 3) Coordinates: - lon (x, y) float64 -99.83 -99.32 -99.79 -99.23 - lat (x, y) float64 42.25 42.21 42.63 42.59 - * time (time) datetime64[ns] 2014-09-06 2014-09-07 2014-09-08 - reference_time datetime64[ns] 2014-09-05 + lon (x, y) float64 32B -99.83 -99.32 -99.79 -99.23 + lat (x, y) float64 32B 42.25 42.21 42.63 42.59 + * time (time) datetime64[ns] 24B 2014-09-06 2014-09-07 2014-09-08 + reference_time datetime64[ns] 8B 2014-09-05 Dimensions without coordinates: x, y Data variables: - temperature (x, y, time) float64 29.11 18.2 22.83 ... 18.28 16.15 26.63 - precipitation (x, y, time) float64 5.68 9.256 0.7104 ... 7.992 4.615 7.805 + temperature (x, y, time) float64 96B 29.11 18.2 22.83 ... 16.15 26.63 + precipitation (x, y, time) float64 96B 5.68 9.256 0.7104 ... 4.615 7.805 """ selection = [] @@ -8741,13 +8741,13 @@ def map_blocks( ... ).chunk() >>> ds = xr.Dataset({"a": array}) >>> ds.map_blocks(calculate_anomaly, template=ds).compute() - + Size: 576B Dimensions: (time: 24) Coordinates: - * time (time) object 1990-01-31 00:00:00 ... 1991-12-31 00:00:00 - month (time) int64 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 + * time (time) object 192B 1990-01-31 00:00:00 ... 1991-12-31 00:00:00 + month (time) int64 192B 1 2 3 4 5 6 7 8 9 10 ... 3 4 5 6 7 8 9 10 11 12 Data variables: - a (time) float64 0.1289 0.1132 -0.0856 ... 0.2287 0.1906 -0.05901 + a (time) float64 192B 0.1289 0.1132 -0.0856 ... 0.1906 -0.05901 Note that one must explicitly use ``args=[]`` and ``kwargs={}`` to pass arguments to the function being applied in ``xr.map_blocks()``: @@ -8757,13 +8757,13 @@ def map_blocks( ... kwargs={"groupby_type": "time.year"}, ... template=ds, ... ) - + Size: 576B Dimensions: (time: 24) Coordinates: - * time (time) object 1990-01-31 00:00:00 ... 1991-12-31 00:00:00 - month (time) int64 dask.array + * time (time) object 192B 1990-01-31 00:00:00 ... 1991-12-31 00:00:00 + month (time) int64 192B dask.array Data variables: - a (time) float64 dask.array + a (time) float64 192B dask.array """ from xarray.core.parallel import map_blocks @@ -9086,11 +9086,11 @@ def pad( -------- >>> ds = xr.Dataset({"foo": ("x", range(5))}) >>> ds.pad(x=(1, 2)) - + Size: 64B Dimensions: (x: 8) Dimensions without coordinates: x Data variables: - foo (x) float64 nan 0.0 1.0 2.0 3.0 4.0 nan nan + foo (x) float64 64B nan 0.0 1.0 2.0 3.0 4.0 nan nan """ pad_width = either_dict_or_kwargs(pad_width, pad_width_kwargs, "pad") @@ -9216,29 +9216,29 @@ def idxmin( ... ) >>> ds = xr.Dataset({"int": array1, "float": array2}) >>> ds.min(dim="x") - + Size: 56B Dimensions: (y: 3) Coordinates: - * y (y) int64 -1 0 1 + * y (y) int64 24B -1 0 1 Data variables: - int int64 -2 - float (y) float64 -2.0 -4.0 1.0 + int int64 8B -2 + float (y) float64 24B -2.0 -4.0 1.0 >>> ds.argmin(dim="x") - + Size: 56B Dimensions: (y: 3) Coordinates: - * y (y) int64 -1 0 1 + * y (y) int64 24B -1 0 1 Data variables: - int int64 4 - float (y) int64 4 0 2 + int int64 8B 4 + float (y) int64 24B 4 0 2 >>> ds.idxmin(dim="x") - + Size: 52B Dimensions: (y: 3) Coordinates: - * y (y) int64 -1 0 1 + * y (y) int64 24B -1 0 1 Data variables: - int >> ds = xr.Dataset({"int": array1, "float": array2}) >>> ds.max(dim="x") - + Size: 56B Dimensions: (y: 3) Coordinates: - * y (y) int64 -1 0 1 + * y (y) int64 24B -1 0 1 Data variables: - int int64 2 - float (y) float64 2.0 2.0 1.0 + int int64 8B 2 + float (y) float64 24B 2.0 2.0 1.0 >>> ds.argmax(dim="x") - + Size: 56B Dimensions: (y: 3) Coordinates: - * y (y) int64 -1 0 1 + * y (y) int64 24B -1 0 1 Data variables: - int int64 1 - float (y) int64 0 2 2 + int int64 8B 1 + float (y) int64 24B 0 2 2 >>> ds.idxmax(dim="x") - + Size: 52B Dimensions: (y: 3) Coordinates: - * y (y) int64 -1 0 1 + * y (y) int64 24B -1 0 1 Data variables: - int Self: ... student=argmin_indices["math_scores"] ... ) >>> min_score_in_math - + Size: 84B array(['Bob', 'Bob', 'Alice'], dtype='>> min_score_in_english = dataset["student"].isel( ... student=argmin_indices["english_scores"] ... ) >>> min_score_in_english - + Size: 84B array(['Charlie', 'Bob', 'Charlie'], dtype=' Self: >>> argmax_indices = dataset.argmax(dim="test") >>> argmax_indices - + Size: 132B Dimensions: (student: 3) Coordinates: - * student (student) >> ds - + Size: 80B Dimensions: (x: 5) Dimensions without coordinates: x Data variables: - a (x) int64 0 1 2 3 4 - b (x) float64 0.0 0.25 0.5 0.75 1.0 + a (x) int64 40B 0 1 2 3 4 + b (x) float64 40B 0.0 0.25 0.5 0.75 1.0 >>> ds.eval("a + b") - + Size: 40B array([0. , 1.25, 2.5 , 3.75, 5. ]) Dimensions without coordinates: x >>> ds.eval("c = a + b") - + Size: 120B Dimensions: (x: 5) Dimensions without coordinates: x Data variables: - a (x) int64 0 1 2 3 4 - b (x) float64 0.0 0.25 0.5 0.75 1.0 - c (x) float64 0.0 1.25 2.5 3.75 5.0 + a (x) int64 40B 0 1 2 3 4 + b (x) float64 40B 0.0 0.25 0.5 0.75 1.0 + c (x) float64 40B 0.0 1.25 2.5 3.75 5.0 """ return pd.eval( @@ -9670,19 +9670,19 @@ def query( >>> b = np.linspace(0, 1, 5) >>> ds = xr.Dataset({"a": ("x", a), "b": ("x", b)}) >>> ds - + Size: 80B Dimensions: (x: 5) Dimensions without coordinates: x Data variables: - a (x) int64 0 1 2 3 4 - b (x) float64 0.0 0.25 0.5 0.75 1.0 + a (x) int64 40B 0 1 2 3 4 + b (x) float64 40B 0.0 0.25 0.5 0.75 1.0 >>> ds.query(x="a > 2") - + Size: 32B Dimensions: (x: 2) Dimensions without coordinates: x Data variables: - a (x) int64 3 4 - b (x) float64 0.75 1.0 + a (x) int64 16B 3 4 + b (x) float64 16B 0.75 1.0 """ # allow queries to be given either as a dict or as kwargs diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index 93f648277ca..fe8167a1f64 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -1215,23 +1215,23 @@ def quantile( ... ) >>> ds = xr.Dataset({"a": da}) >>> da.groupby("x").quantile(0) - + Size: 64B array([[0.7, 4.2, 0.7, 1.5], [6.5, 7.3, 2.6, 1.9]]) Coordinates: - * y (y) int64 1 1 2 2 - quantile float64 0.0 - * x (x) int64 0 1 + * y (y) int64 32B 1 1 2 2 + quantile float64 8B 0.0 + * x (x) int64 16B 0 1 >>> ds.groupby("y").quantile(0, dim=...) - + Size: 40B Dimensions: (y: 2) Coordinates: - quantile float64 0.0 - * y (y) int64 1 2 + quantile float64 8B 0.0 + * y (y) int64 16B 1 2 Data variables: - a (y) float64 0.7 0.7 + a (y) float64 16B 0.7 0.7 >>> da.groupby("x").quantile([0, 0.5, 1]) - + Size: 192B array([[[0.7 , 1. , 1.3 ], [4.2 , 6.3 , 8.4 ], [0.7 , 5.05, 9.4 ], @@ -1242,17 +1242,17 @@ def quantile( [2.6 , 2.6 , 2.6 ], [1.9 , 1.9 , 1.9 ]]]) Coordinates: - * y (y) int64 1 1 2 2 - * quantile (quantile) float64 0.0 0.5 1.0 - * x (x) int64 0 1 + * y (y) int64 32B 1 1 2 2 + * quantile (quantile) float64 24B 0.0 0.5 1.0 + * x (x) int64 16B 0 1 >>> ds.groupby("y").quantile([0, 0.5, 1], dim=...) - + Size: 88B Dimensions: (y: 2, quantile: 3) Coordinates: - * quantile (quantile) float64 0.0 0.5 1.0 - * y (y) int64 1 2 + * quantile (quantile) float64 24B 0.0 0.5 1.0 + * y (y) int64 16B 1 2 Data variables: - a (y, quantile) float64 0.7 5.35 8.4 0.7 2.25 9.4 + a (y, quantile) float64 48B 0.7 5.35 8.4 0.7 2.25 9.4 References ---------- diff --git a/xarray/core/merge.py b/xarray/core/merge.py index 350e3895061..a96922072be 100644 --- a/xarray/core/merge.py +++ b/xarray/core/merge.py @@ -839,124 +839,124 @@ def merge( ... ) >>> x - + Size: 32B array([[1., 2.], [3., 5.]]) Coordinates: - * lat (lat) float64 35.0 40.0 - * lon (lon) float64 100.0 120.0 + * lat (lat) float64 16B 35.0 40.0 + * lon (lon) float64 16B 100.0 120.0 >>> y - + Size: 32B array([[5., 6.], [7., 8.]]) Coordinates: - * lat (lat) float64 35.0 42.0 - * lon (lon) float64 100.0 150.0 + * lat (lat) float64 16B 35.0 42.0 + * lon (lon) float64 16B 100.0 150.0 >>> z - + Size: 32B array([[0., 3.], [4., 9.]]) Coordinates: - * time (time) float64 30.0 60.0 - * lon (lon) float64 100.0 150.0 + * time (time) float64 16B 30.0 60.0 + * lon (lon) float64 16B 100.0 150.0 >>> xr.merge([x, y, z]) - + Size: 256B Dimensions: (lat: 3, lon: 3, time: 2) Coordinates: - * lat (lat) float64 35.0 40.0 42.0 - * lon (lon) float64 100.0 120.0 150.0 - * time (time) float64 30.0 60.0 + * lat (lat) float64 24B 35.0 40.0 42.0 + * lon (lon) float64 24B 100.0 120.0 150.0 + * time (time) float64 16B 30.0 60.0 Data variables: - var1 (lat, lon) float64 1.0 2.0 nan 3.0 5.0 nan nan nan nan - var2 (lat, lon) float64 5.0 nan 6.0 nan nan nan 7.0 nan 8.0 - var3 (time, lon) float64 0.0 nan 3.0 4.0 nan 9.0 + var1 (lat, lon) float64 72B 1.0 2.0 nan 3.0 5.0 nan nan nan nan + var2 (lat, lon) float64 72B 5.0 nan 6.0 nan nan nan 7.0 nan 8.0 + var3 (time, lon) float64 48B 0.0 nan 3.0 4.0 nan 9.0 >>> xr.merge([x, y, z], compat="identical") - + Size: 256B Dimensions: (lat: 3, lon: 3, time: 2) Coordinates: - * lat (lat) float64 35.0 40.0 42.0 - * lon (lon) float64 100.0 120.0 150.0 - * time (time) float64 30.0 60.0 + * lat (lat) float64 24B 35.0 40.0 42.0 + * lon (lon) float64 24B 100.0 120.0 150.0 + * time (time) float64 16B 30.0 60.0 Data variables: - var1 (lat, lon) float64 1.0 2.0 nan 3.0 5.0 nan nan nan nan - var2 (lat, lon) float64 5.0 nan 6.0 nan nan nan 7.0 nan 8.0 - var3 (time, lon) float64 0.0 nan 3.0 4.0 nan 9.0 + var1 (lat, lon) float64 72B 1.0 2.0 nan 3.0 5.0 nan nan nan nan + var2 (lat, lon) float64 72B 5.0 nan 6.0 nan nan nan 7.0 nan 8.0 + var3 (time, lon) float64 48B 0.0 nan 3.0 4.0 nan 9.0 >>> xr.merge([x, y, z], compat="equals") - + Size: 256B Dimensions: (lat: 3, lon: 3, time: 2) Coordinates: - * lat (lat) float64 35.0 40.0 42.0 - * lon (lon) float64 100.0 120.0 150.0 - * time (time) float64 30.0 60.0 + * lat (lat) float64 24B 35.0 40.0 42.0 + * lon (lon) float64 24B 100.0 120.0 150.0 + * time (time) float64 16B 30.0 60.0 Data variables: - var1 (lat, lon) float64 1.0 2.0 nan 3.0 5.0 nan nan nan nan - var2 (lat, lon) float64 5.0 nan 6.0 nan nan nan 7.0 nan 8.0 - var3 (time, lon) float64 0.0 nan 3.0 4.0 nan 9.0 + var1 (lat, lon) float64 72B 1.0 2.0 nan 3.0 5.0 nan nan nan nan + var2 (lat, lon) float64 72B 5.0 nan 6.0 nan nan nan 7.0 nan 8.0 + var3 (time, lon) float64 48B 0.0 nan 3.0 4.0 nan 9.0 >>> xr.merge([x, y, z], compat="equals", fill_value=-999.0) - + Size: 256B Dimensions: (lat: 3, lon: 3, time: 2) Coordinates: - * lat (lat) float64 35.0 40.0 42.0 - * lon (lon) float64 100.0 120.0 150.0 - * time (time) float64 30.0 60.0 + * lat (lat) float64 24B 35.0 40.0 42.0 + * lon (lon) float64 24B 100.0 120.0 150.0 + * time (time) float64 16B 30.0 60.0 Data variables: - var1 (lat, lon) float64 1.0 2.0 -999.0 3.0 ... -999.0 -999.0 -999.0 - var2 (lat, lon) float64 5.0 -999.0 6.0 -999.0 ... -999.0 7.0 -999.0 8.0 - var3 (time, lon) float64 0.0 -999.0 3.0 4.0 -999.0 9.0 + var1 (lat, lon) float64 72B 1.0 2.0 -999.0 3.0 ... -999.0 -999.0 -999.0 + var2 (lat, lon) float64 72B 5.0 -999.0 6.0 -999.0 ... 7.0 -999.0 8.0 + var3 (time, lon) float64 48B 0.0 -999.0 3.0 4.0 -999.0 9.0 >>> xr.merge([x, y, z], join="override") - + Size: 144B Dimensions: (lat: 2, lon: 2, time: 2) Coordinates: - * lat (lat) float64 35.0 40.0 - * lon (lon) float64 100.0 120.0 - * time (time) float64 30.0 60.0 + * lat (lat) float64 16B 35.0 40.0 + * lon (lon) float64 16B 100.0 120.0 + * time (time) float64 16B 30.0 60.0 Data variables: - var1 (lat, lon) float64 1.0 2.0 3.0 5.0 - var2 (lat, lon) float64 5.0 6.0 7.0 8.0 - var3 (time, lon) float64 0.0 3.0 4.0 9.0 + var1 (lat, lon) float64 32B 1.0 2.0 3.0 5.0 + var2 (lat, lon) float64 32B 5.0 6.0 7.0 8.0 + var3 (time, lon) float64 32B 0.0 3.0 4.0 9.0 >>> xr.merge([x, y, z], join="inner") - + Size: 64B Dimensions: (lat: 1, lon: 1, time: 2) Coordinates: - * lat (lat) float64 35.0 - * lon (lon) float64 100.0 - * time (time) float64 30.0 60.0 + * lat (lat) float64 8B 35.0 + * lon (lon) float64 8B 100.0 + * time (time) float64 16B 30.0 60.0 Data variables: - var1 (lat, lon) float64 1.0 - var2 (lat, lon) float64 5.0 - var3 (time, lon) float64 0.0 4.0 + var1 (lat, lon) float64 8B 1.0 + var2 (lat, lon) float64 8B 5.0 + var3 (time, lon) float64 16B 0.0 4.0 >>> xr.merge([x, y, z], compat="identical", join="inner") - + Size: 64B Dimensions: (lat: 1, lon: 1, time: 2) Coordinates: - * lat (lat) float64 35.0 - * lon (lon) float64 100.0 - * time (time) float64 30.0 60.0 + * lat (lat) float64 8B 35.0 + * lon (lon) float64 8B 100.0 + * time (time) float64 16B 30.0 60.0 Data variables: - var1 (lat, lon) float64 1.0 - var2 (lat, lon) float64 5.0 - var3 (time, lon) float64 0.0 4.0 + var1 (lat, lon) float64 8B 1.0 + var2 (lat, lon) float64 8B 5.0 + var3 (time, lon) float64 16B 0.0 4.0 >>> xr.merge([x, y, z], compat="broadcast_equals", join="outer") - + Size: 256B Dimensions: (lat: 3, lon: 3, time: 2) Coordinates: - * lat (lat) float64 35.0 40.0 42.0 - * lon (lon) float64 100.0 120.0 150.0 - * time (time) float64 30.0 60.0 + * lat (lat) float64 24B 35.0 40.0 42.0 + * lon (lon) float64 24B 100.0 120.0 150.0 + * time (time) float64 16B 30.0 60.0 Data variables: - var1 (lat, lon) float64 1.0 2.0 nan 3.0 5.0 nan nan nan nan - var2 (lat, lon) float64 5.0 nan 6.0 nan nan nan 7.0 nan 8.0 - var3 (time, lon) float64 0.0 nan 3.0 4.0 nan 9.0 + var1 (lat, lon) float64 72B 1.0 2.0 nan 3.0 5.0 nan nan nan nan + var2 (lat, lon) float64 72B 5.0 nan 6.0 nan nan nan 7.0 nan 8.0 + var3 (time, lon) float64 48B 0.0 nan 3.0 4.0 nan 9.0 >>> xr.merge([x, y, z], join="exact") Traceback (most recent call last): diff --git a/xarray/core/options.py b/xarray/core/options.py index d116c350991..4b8dd97e51f 100644 --- a/xarray/core/options.py +++ b/xarray/core/options.py @@ -255,12 +255,13 @@ class set_options: >>> with xr.set_options(display_width=40): ... print(ds) ... - + Size: 8kB Dimensions: (x: 1000) Coordinates: - * x (x) int64 0 1 2 ... 998 999 + * x (x) int64 8kB 0 1 ... 999 Data variables: *empty* + *empty* Or to set global options: diff --git a/xarray/core/parallel.py b/xarray/core/parallel.py index 3b47520a78c..9a2bb41fab0 100644 --- a/xarray/core/parallel.py +++ b/xarray/core/parallel.py @@ -306,15 +306,15 @@ def map_blocks( ... coords={"time": time, "month": month}, ... ).chunk() >>> array.map_blocks(calculate_anomaly, template=array).compute() - + Size: 192B array([ 0.12894847, 0.11323072, -0.0855964 , -0.09334032, 0.26848862, 0.12382735, 0.22460641, 0.07650108, -0.07673453, -0.22865714, -0.19063865, 0.0590131 , -0.12894847, -0.11323072, 0.0855964 , 0.09334032, -0.26848862, -0.12382735, -0.22460641, -0.07650108, 0.07673453, 0.22865714, 0.19063865, -0.0590131 ]) Coordinates: - * time (time) object 1990-01-31 00:00:00 ... 1991-12-31 00:00:00 - month (time) int64 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 + * time (time) object 192B 1990-01-31 00:00:00 ... 1991-12-31 00:00:00 + month (time) int64 192B 1 2 3 4 5 6 7 8 9 10 ... 3 4 5 6 7 8 9 10 11 12 Note that one must explicitly use ``args=[]`` and ``kwargs={}`` to pass arguments to the function being applied in ``xr.map_blocks()``: @@ -324,11 +324,11 @@ def map_blocks( ... kwargs={"groupby_type": "time.year"}, ... template=array, ... ) # doctest: +ELLIPSIS - + Size: 192B dask.array<-calculate_anomaly, shape=(24,), dtype=float64, chunksize=(24,), chunktype=numpy.ndarray> Coordinates: - * time (time) object 1990-01-31 00:00:00 ... 1991-12-31 00:00:00 - month (time) int64 dask.array + * time (time) object 192B 1990-01-31 00:00:00 ... 1991-12-31 00:00:00 + month (time) int64 192B dask.array """ def _wrapper( diff --git a/xarray/core/rolling.py b/xarray/core/rolling.py index 2188599962a..3723f42ac55 100644 --- a/xarray/core/rolling.py +++ b/xarray/core/rolling.py @@ -345,7 +345,7 @@ def construct( >>> rolling = da.rolling(b=3) >>> rolling.construct("window_dim") - + Size: 192B array([[[nan, nan, 0.], [nan, 0., 1.], [ 0., 1., 2.], @@ -359,7 +359,7 @@ def construct( >>> rolling = da.rolling(b=3, center=True) >>> rolling.construct("window_dim") - + Size: 192B array([[[nan, 0., 1.], [ 0., 1., 2.], [ 1., 2., 3.], @@ -451,7 +451,7 @@ def reduce( >>> da = xr.DataArray(np.arange(8).reshape(2, 4), dims=("a", "b")) >>> rolling = da.rolling(b=3) >>> rolling.construct("window_dim") - + Size: 192B array([[[nan, nan, 0.], [nan, 0., 1.], [ 0., 1., 2.], @@ -464,14 +464,14 @@ def reduce( Dimensions without coordinates: a, b, window_dim >>> rolling.reduce(np.sum) - + Size: 64B array([[nan, nan, 3., 6.], [nan, nan, 15., 18.]]) Dimensions without coordinates: a, b >>> rolling = da.rolling(b=3, min_periods=1) >>> rolling.reduce(np.nansum) - + Size: 64B array([[ 0., 1., 3., 6.], [ 4., 9., 15., 18.]]) Dimensions without coordinates: a, b @@ -1014,7 +1014,7 @@ def construct( -------- >>> da = xr.DataArray(np.arange(24), dims="time") >>> da.coarsen(time=12).construct(time=("year", "month")) - + Size: 192B array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]]) Dimensions without coordinates: year, month @@ -1170,7 +1170,7 @@ def reduce( >>> da = xr.DataArray(np.arange(8).reshape(2, 4), dims=("a", "b")) >>> coarsen = da.coarsen(b=2) >>> coarsen.reduce(np.sum) - + Size: 32B array([[ 1, 5], [ 9, 13]]) Dimensions without coordinates: a, b diff --git a/xarray/core/rolling_exp.py b/xarray/core/rolling_exp.py index 144e26a86b2..233bb2e37d9 100644 --- a/xarray/core/rolling_exp.py +++ b/xarray/core/rolling_exp.py @@ -116,7 +116,7 @@ def mean(self, keep_attrs: bool | None = None) -> T_DataWithCoords: -------- >>> da = xr.DataArray([1, 1, 2, 2, 2], dims="x") >>> da.rolling_exp(x=2, window_type="span").mean() - + Size: 40B array([1. , 1. , 1.69230769, 1.9 , 1.96694215]) Dimensions without coordinates: x """ @@ -154,7 +154,7 @@ def sum(self, keep_attrs: bool | None = None) -> T_DataWithCoords: -------- >>> da = xr.DataArray([1, 1, 2, 2, 2], dims="x") >>> da.rolling_exp(x=2, window_type="span").sum() - + Size: 40B array([1. , 1.33333333, 2.44444444, 2.81481481, 2.9382716 ]) Dimensions without coordinates: x """ @@ -187,7 +187,7 @@ def std(self) -> T_DataWithCoords: -------- >>> da = xr.DataArray([1, 1, 2, 2, 2], dims="x") >>> da.rolling_exp(x=2, window_type="span").std() - + Size: 40B array([ nan, 0. , 0.67936622, 0.42966892, 0.25389527]) Dimensions without coordinates: x """ @@ -221,7 +221,7 @@ def var(self) -> T_DataWithCoords: -------- >>> da = xr.DataArray([1, 1, 2, 2, 2], dims="x") >>> da.rolling_exp(x=2, window_type="span").var() - + Size: 40B array([ nan, 0. , 0.46153846, 0.18461538, 0.06446281]) Dimensions without coordinates: x """ @@ -253,7 +253,7 @@ def cov(self, other: T_DataWithCoords) -> T_DataWithCoords: -------- >>> da = xr.DataArray([1, 1, 2, 2, 2], dims="x") >>> da.rolling_exp(x=2, window_type="span").cov(da**2) - + Size: 40B array([ nan, 0. , 1.38461538, 0.55384615, 0.19338843]) Dimensions without coordinates: x """ @@ -287,7 +287,7 @@ def corr(self, other: T_DataWithCoords) -> T_DataWithCoords: -------- >>> da = xr.DataArray([1, 1, 2, 2, 2], dims="x") >>> da.rolling_exp(x=2, window_type="span").corr(da.shift(x=1)) - + Size: 40B array([ nan, nan, nan, 0.4330127 , 0.48038446]) Dimensions without coordinates: x """ diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 94324c1d57f..7d0e72d1833 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -2120,7 +2120,7 @@ def rolling_window( -------- >>> v = Variable(("a", "b"), np.arange(8).reshape((2, 4))) >>> v.rolling_window("b", 3, "window_dim") - + Size: 192B array([[[nan, nan, 0.], [nan, 0., 1.], [ 0., 1., 2.], @@ -2132,7 +2132,7 @@ def rolling_window( [ 5., 6., 7.]]]) >>> v.rolling_window("b", 3, "window_dim", center=True) - + Size: 192B array([[[nan, 0., 1.], [ 0., 1., 2.], [ 1., 2., 3.], @@ -2309,10 +2309,10 @@ def isnull(self, keep_attrs: bool | None = None): -------- >>> var = xr.Variable("x", [1, np.nan, 3]) >>> var - + Size: 24B array([ 1., nan, 3.]) >>> var.isnull() - + Size: 3B array([False, True, False]) """ from xarray.core.computation import apply_ufunc @@ -2343,10 +2343,10 @@ def notnull(self, keep_attrs: bool | None = None): -------- >>> var = xr.Variable("x", [1, np.nan, 3]) >>> var - + Size: 24B array([ 1., nan, 3.]) >>> var.notnull() - + Size: 3B array([ True, False, True]) """ from xarray.core.computation import apply_ufunc diff --git a/xarray/datatree_/datatree/datatree.py b/xarray/datatree_/datatree/datatree.py index c86c2e2e3e8..0ce382a6460 100644 --- a/xarray/datatree_/datatree/datatree.py +++ b/xarray/datatree_/datatree/datatree.py @@ -277,19 +277,19 @@ def map( >>> da = xr.DataArray(np.random.randn(2, 3)) >>> ds = xr.Dataset({"foo": da, "bar": ("x", [-1, 2])}) >>> ds - + Size: 64B Dimensions: (dim_0: 2, dim_1: 3, x: 2) Dimensions without coordinates: dim_0, dim_1, x Data variables: - foo (dim_0, dim_1) float64 1.764 0.4002 0.9787 2.241 1.868 -0.9773 - bar (x) int64 -1 2 + foo (dim_0, dim_1) float64 48B 1.764 0.4002 0.9787 2.241 1.868 -0.9773 + bar (x) int64 16B -1 2 >>> ds.map(np.fabs) - + Size: 64B Dimensions: (dim_0: 2, dim_1: 3, x: 2) Dimensions without coordinates: dim_0, dim_1, x Data variables: - foo (dim_0, dim_1) float64 1.764 0.4002 0.9787 2.241 1.868 0.9773 - bar (x) float64 1.0 2.0 + foo (dim_0, dim_1) float64 48B 1.764 0.4002 0.9787 2.241 1.868 0.9773 + bar (x) float64 16B 1.0 2.0 """ # Copied from xarray.Dataset so as not to call type(self), which causes problems (see datatree GH188). diff --git a/xarray/namedarray/_aggregations.py b/xarray/namedarray/_aggregations.py index 76dfb18d068..6ee4dadccc0 100644 --- a/xarray/namedarray/_aggregations.py +++ b/xarray/namedarray/_aggregations.py @@ -65,11 +65,11 @@ def count( ... np.array([1, 2, 3, 0, 2, np.nan]), ... ) >>> na - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) >>> na.count() - + Size: 8B array(5) """ return self.reduce( @@ -119,11 +119,11 @@ def all( ... np.array([True, True, True, True, True, False], dtype=bool), ... ) >>> na - + Size: 6B array([ True, True, True, True, True, False]) >>> na.all() - + Size: 1B array(False) """ return self.reduce( @@ -173,11 +173,11 @@ def any( ... np.array([True, True, True, True, True, False], dtype=bool), ... ) >>> na - + Size: 6B array([ True, True, True, True, True, False]) >>> na.any() - + Size: 1B array(True) """ return self.reduce( @@ -234,17 +234,17 @@ def max( ... np.array([1, 2, 3, 0, 2, np.nan]), ... ) >>> na - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) >>> na.max() - + Size: 8B array(3.) Use ``skipna`` to control whether NaNs are ignored. >>> na.max(skipna=False) - + Size: 8B array(nan) """ return self.reduce( @@ -302,17 +302,17 @@ def min( ... np.array([1, 2, 3, 0, 2, np.nan]), ... ) >>> na - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) >>> na.min() - + Size: 8B array(0.) Use ``skipna`` to control whether NaNs are ignored. >>> na.min(skipna=False) - + Size: 8B array(nan) """ return self.reduce( @@ -374,17 +374,17 @@ def mean( ... np.array([1, 2, 3, 0, 2, np.nan]), ... ) >>> na - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) >>> na.mean() - + Size: 8B array(1.6) Use ``skipna`` to control whether NaNs are ignored. >>> na.mean(skipna=False) - + Size: 8B array(nan) """ return self.reduce( @@ -453,23 +453,23 @@ def prod( ... np.array([1, 2, 3, 0, 2, np.nan]), ... ) >>> na - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) >>> na.prod() - + Size: 8B array(0.) Use ``skipna`` to control whether NaNs are ignored. >>> na.prod(skipna=False) - + Size: 8B array(nan) Specify ``min_count`` for finer control over when NaNs are ignored. >>> na.prod(skipna=True, min_count=2) - + Size: 8B array(0.) """ return self.reduce( @@ -539,23 +539,23 @@ def sum( ... np.array([1, 2, 3, 0, 2, np.nan]), ... ) >>> na - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) >>> na.sum() - + Size: 8B array(8.) Use ``skipna`` to control whether NaNs are ignored. >>> na.sum(skipna=False) - + Size: 8B array(nan) Specify ``min_count`` for finer control over when NaNs are ignored. >>> na.sum(skipna=True, min_count=2) - + Size: 8B array(8.) """ return self.reduce( @@ -622,23 +622,23 @@ def std( ... np.array([1, 2, 3, 0, 2, np.nan]), ... ) >>> na - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) >>> na.std() - + Size: 8B array(1.0198039) Use ``skipna`` to control whether NaNs are ignored. >>> na.std(skipna=False) - + Size: 8B array(nan) Specify ``ddof=1`` for an unbiased estimate. >>> na.std(skipna=True, ddof=1) - + Size: 8B array(1.14017543) """ return self.reduce( @@ -705,23 +705,23 @@ def var( ... np.array([1, 2, 3, 0, 2, np.nan]), ... ) >>> na - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) >>> na.var() - + Size: 8B array(1.04) Use ``skipna`` to control whether NaNs are ignored. >>> na.var(skipna=False) - + Size: 8B array(nan) Specify ``ddof=1`` for an unbiased estimate. >>> na.var(skipna=True, ddof=1) - + Size: 8B array(1.3) """ return self.reduce( @@ -784,17 +784,17 @@ def median( ... np.array([1, 2, 3, 0, 2, np.nan]), ... ) >>> na - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) >>> na.median() - + Size: 8B array(2.) Use ``skipna`` to control whether NaNs are ignored. >>> na.median(skipna=False) - + Size: 8B array(nan) """ return self.reduce( @@ -856,17 +856,17 @@ def cumsum( ... np.array([1, 2, 3, 0, 2, np.nan]), ... ) >>> na - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) >>> na.cumsum() - + Size: 48B array([1., 3., 6., 6., 8., 8.]) Use ``skipna`` to control whether NaNs are ignored. >>> na.cumsum(skipna=False) - + Size: 48B array([ 1., 3., 6., 6., 8., nan]) """ return self.reduce( @@ -928,17 +928,17 @@ def cumprod( ... np.array([1, 2, 3, 0, 2, np.nan]), ... ) >>> na - + Size: 48B array([ 1., 2., 3., 0., 2., nan]) >>> na.cumprod() - + Size: 48B array([1., 2., 6., 0., 0., 0.]) Use ``skipna`` to control whether NaNs are ignored. >>> na.cumprod(skipna=False) - + Size: 48B array([ 1., 2., 6., 0., 0., nan]) """ return self.reduce( diff --git a/xarray/namedarray/_array_api.py b/xarray/namedarray/_array_api.py index 2ad539bad18..977d011c685 100644 --- a/xarray/namedarray/_array_api.py +++ b/xarray/namedarray/_array_api.py @@ -70,10 +70,10 @@ def astype( -------- >>> narr = NamedArray(("x",), nxp.asarray([1.5, 2.5])) >>> narr - + Size: 16B Array([1.5, 2.5], dtype=float64) >>> astype(narr, np.dtype(np.int32)) - + Size: 8B Array([1, 2], dtype=int32) """ if isinstance(x._data, _arrayapi): @@ -111,7 +111,7 @@ def imag( -------- >>> narr = NamedArray(("x",), np.asarray([1.0 + 2j, 2 + 4j])) # TODO: Use nxp >>> imag(narr) - + Size: 16B array([2., 4.]) """ xp = _get_data_namespace(x) @@ -143,7 +143,7 @@ def real( -------- >>> narr = NamedArray(("x",), np.asarray([1.0 + 2j, 2 + 4j])) # TODO: Use nxp >>> real(narr) - + Size: 16B array([1., 2.]) """ xp = _get_data_namespace(x) @@ -181,11 +181,11 @@ def expand_dims( -------- >>> x = NamedArray(("x", "y"), nxp.asarray([[1.0, 2.0], [3.0, 4.0]])) >>> expand_dims(x) - + Size: 32B Array([[[1., 2.], [3., 4.]]], dtype=float64) >>> expand_dims(x, dim="z") - + Size: 32B Array([[[1., 2.], [3., 4.]]], dtype=float64) """ diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 903780b1137..61b85121659 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -1495,28 +1495,28 @@ def values(self) -> DataArray | None: -------- >>> a = xr.DataArray(["b", "a", "a", "b", "c"]) >>> _Normalize(a).values - + Size: 40B array([3, 1, 1, 3, 5]) Dimensions without coordinates: dim_0 >>> _Normalize(a, width=(18, 36, 72)).values - + Size: 40B array([45., 18., 18., 45., 72.]) Dimensions without coordinates: dim_0 >>> a = xr.DataArray([0.5, 0, 0, 0.5, 2, 3]) >>> _Normalize(a).values - + Size: 48B array([0.5, 0. , 0. , 0.5, 2. , 3. ]) Dimensions without coordinates: dim_0 >>> _Normalize(a, width=(18, 36, 72)).values - + Size: 48B array([27., 18., 18., 27., 54., 72.]) Dimensions without coordinates: dim_0 >>> _Normalize(a * 0, width=(18, 36, 72)).values - + Size: 48B array([36., 36., 36., 36., 36., 36.]) Dimensions without coordinates: dim_0 From 859daead0ddb6da642e817e91973fe2127c71554 Mon Sep 17 00:00:00 2001 From: eschalk Date: Mon, 5 Feb 2024 23:45:31 +0100 Subject: [PATCH 10/18] Revert "Remove problematic backslashes" This reverts commit 85f6ee4f2d9d820d39ca9ab64619a098a791a7f4. --- xarray/backends/api.py | 34 ++++++++++++++++------------------ xarray/core/combine.py | 8 ++++---- xarray/core/computation.py | 13 +++++-------- xarray/core/concat.py | 2 +- xarray/core/dataarray.py | 38 +++++++++++++++++++------------------- xarray/core/dataset.py | 26 +++++++++++++------------- xarray/core/merge.py | 8 ++++---- xarray/core/resample.py | 2 +- xarray/core/variable.py | 18 ++++++++++-------- 9 files changed, 73 insertions(+), 76 deletions(-) diff --git a/xarray/backends/api.py b/xarray/backends/api.py index c1160850087..d5ff1d9fbcf 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -419,8 +419,8 @@ def open_dataset( ends with .gz, in which case the file is gunzipped and opened with scipy.io.netcdf (only netCDF3 supported). Byte-strings or file-like objects are opened by scipy.io.netcdf (netCDF3) or h5py (netCDF4/HDF). - engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio",, - "zarr", None}, installed backend, + engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio", \ + "zarr", None}, installed backend \ or subclass of xarray.backends.BackendEntrypoint, optional Engine to use when reading files. If not provided, the default engine is chosen based on available dependencies, with a preference for @@ -626,8 +626,8 @@ def open_dataarray( ends with .gz, in which case the file is gunzipped and opened with scipy.io.netcdf (only netCDF3 supported). Byte-strings or file-like objects are opened by scipy.io.netcdf (netCDF3) or h5py (netCDF4/HDF). - engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio",, - "zarr", None}, installed backend, + engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio", \ + "zarr", None}, installed backend \ or subclass of xarray.backends.BackendEntrypoint, optional Engine to use when reading files. If not provided, the default engine is chosen based on available dependencies, with a preference for @@ -791,15 +791,13 @@ def open_dataarray( def open_mfdataset( paths: str | NestedSequence[str | os.PathLike], chunks: T_Chunks | None = None, - concat_dim: ( - str - | DataArray - | Index - | Sequence[str] - | Sequence[DataArray] - | Sequence[Index] - | None - ) = None, + concat_dim: str + | DataArray + | Index + | Sequence[str] + | Sequence[DataArray] + | Sequence[Index] + | None = None, compat: CompatOptions = "no_conflicts", preprocess: Callable[[Dataset], Dataset] | None = None, engine: T_Engine | None = None, @@ -849,7 +847,7 @@ def open_mfdataset( combine : {"by_coords", "nested"}, optional Whether ``xarray.combine_by_coords`` or ``xarray.combine_nested`` is used to combine all the data. Default is to use ``xarray.combine_by_coords``. - compat : {"identical", "equals", "broadcast_equals",, + compat : {"identical", "equals", "broadcast_equals", \ "no_conflicts", "override"}, default: "no_conflicts" String indicating how to compare variables of the same name for potential conflicts when merging: @@ -868,8 +866,8 @@ def open_mfdataset( If provided, call this function on each dataset prior to concatenation. You can find the file-name from which each dataset was loaded in ``ds.encoding["source"]``. - engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio",, - "zarr", None}, installed backend, + engine : {"netcdf4", "scipy", "pydap", "h5netcdf", "pynio", \ + "zarr", None}, installed backend \ or subclass of xarray.backends.BackendEntrypoint, optional Engine to use when reading files. If not provided, the default engine is chosen based on available dependencies, with a preference for @@ -919,7 +917,7 @@ def open_mfdataset( Path of the file used to read global attributes from. By default global attributes are read from the first file provided, with wildcard matches sorted by filename. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts",, + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ "override"} or callable, default: "override" A callable or a string indicating how to combine attrs of the objects being merged: @@ -1392,7 +1390,7 @@ def save_mfdataset( mode : {"w", "a"}, optional Write ("w") or append ("a") mode. If mode="w", any existing file at these locations will be overwritten. - format : {"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT",, + format : {"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT", \ "NETCDF3_CLASSIC"}, optional **kwargs : additional arguments are passed along to ``to_netcdf`` diff --git a/xarray/core/combine.py b/xarray/core/combine.py index f3c73e9b319..98a90dba761 100644 --- a/xarray/core/combine.py +++ b/xarray/core/combine.py @@ -372,7 +372,7 @@ def _nested_combine( def combine_nested( datasets: DATASET_HYPERCUBE, - concat_dim: str | DataArray | None | Sequence[str | DataArray | pd.Index | None], + concat_dim: (str | DataArray | None | Sequence[str | DataArray | pd.Index | None]), compat: str = "no_conflicts", data_vars: str = "all", coords: str = "different", @@ -413,7 +413,7 @@ def combine_nested( nested-list input along which to merge. Must be the same length as the depth of the list passed to ``datasets``. - compat : {"identical", "equals", "broadcast_equals", + compat : {"identical", "equals", "broadcast_equals", \ "no_conflicts", "override"}, optional String indicating how to compare variables of the same name for potential merge conflicts: @@ -448,7 +448,7 @@ def combine_nested( - "override": if indexes are of same size, rewrite indexes to be those of the first object with that dimension. Indexes for the same dimension must have the same size in all objects. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ "override"} or callable, default: "drop" A callable or a string indicating how to combine attrs of the objects being merged: @@ -738,7 +738,7 @@ def combine_by_coords( those of the first object with that dimension. Indexes for the same dimension must have the same size in all objects. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ "override"} or callable, default: "no_conflicts" A callable or a string indicating how to combine attrs of the objects being merged: diff --git a/xarray/core/computation.py b/xarray/core/computation.py index 89d757bf30a..5e11ab20223 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1,7 +1,6 @@ """ Functions for applying functions that act on arrays to xarray's labeled data. """ - from __future__ import annotations import functools @@ -224,7 +223,7 @@ def build_output_coords_and_indexes( exclude_dims : set, optional Dimensions excluded from the operation. Coordinates along these dimensions are dropped. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ "override"} or callable, default: "drop" A callable or a string indicating how to combine attrs of the objects being merged: @@ -732,11 +731,9 @@ def apply_variable_ufunc( output_dims = [broadcast_dims + out for out in signature.output_core_dims] input_data = [ - ( - broadcast_compat_data(arg, broadcast_dims, core_dims) - if isinstance(arg, Variable) - else arg - ) + broadcast_compat_data(arg, broadcast_dims, core_dims) + if isinstance(arg, Variable) + else arg for arg, core_dims in zip(args, signature.input_core_dims) ] @@ -934,7 +931,7 @@ def apply_ufunc( the style of NumPy universal functions [1]_ (if this is not the case, set ``vectorize=True``). If this function returns multiple outputs, you must set ``output_core_dims`` as well. - *args : Dataset, DataArray, DataArrayGroupBy, DatasetGroupBy, Variable, + *args : Dataset, DataArray, DataArrayGroupBy, DatasetGroupBy, Variable, \ numpy.ndarray, dask.array.Array or scalar Mix of labeled and/or unlabeled arrays to which to apply the function. input_core_dims : sequence of sequence, optional diff --git a/xarray/core/concat.py b/xarray/core/concat.py index 86966966e39..8411e136cc2 100644 --- a/xarray/core/concat.py +++ b/xarray/core/concat.py @@ -148,7 +148,7 @@ def concat( - "override": if indexes are of same size, rewrite indexes to be those of the first object with that dimension. Indexes for the same dimension must have the same size in all objects. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ "override"} or callable, default: "override" A callable or a string indicating how to combine attrs of the objects being merged: diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 763eab3a5ea..e644a27e3e2 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -3437,7 +3437,7 @@ def interpolate_na( ---------- dim : Hashable or None, optional Specifies the dimension along which to interpolate. - method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial", + method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial", \ "barycentric", "krogh", "pchip", "spline", "akima"}, default: "linear" String indicating which method to use for interpolation: @@ -3995,7 +3995,7 @@ def to_netcdf( Write ('w') or append ('a') mode. If mode='w', any existing file at this location will be overwritten. If mode='a', existing variables will be overwritten. - format : {"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT", + format : {"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT", \ "NETCDF3_CLASSIC"}, optional File format for the resulting netCDF file: @@ -4983,12 +4983,10 @@ def dot( def sortby( self, - variables: ( - Hashable - | DataArray - | Sequence[Hashable | DataArray] - | Callable[[Self], Hashable | DataArray | Sequence[Hashable | DataArray]] - ), + variables: Hashable + | DataArray + | Sequence[Hashable | DataArray] + | Callable[[Self], Hashable | DataArray | Sequence[Hashable | DataArray]], ascending: bool = True, ) -> Self: """Sort object by labels or values (along an axis). @@ -5234,7 +5232,7 @@ def differentiate( edge_order: Literal[1, 2] = 1, datetime_unit: DatetimeUnitOptions = None, ) -> Self: - """Differentiate the array with the second order accurate central + """ Differentiate the array with the second order accurate central differences. .. note:: @@ -5247,7 +5245,7 @@ def differentiate( The coordinate to be used to compute the gradient. edge_order : {1, 2}, default: 1 N-th order accurate differences at the boundaries. - datetime_unit : {"W", "D", "h", "m", "s", "ms", + datetime_unit : {"W", "D", "h", "m", "s", "ms", \ "us", "ns", "ps", "fs", "as", None}, optional Unit to compute gradient. Only valid for datetime coordinate. "Y" and "M" are not available as datetime_unit. @@ -5306,7 +5304,7 @@ def integrate( ---------- coord : Hashable, or sequence of Hashable Coordinate(s) used for the integration. - datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', + datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', \ 'ps', 'fs', 'as', None}, optional Specify the unit if a datetime coordinate is used. @@ -5363,7 +5361,7 @@ def cumulative_integrate( ---------- coord : Hashable, or sequence of Hashable Coordinate(s) used for the integration. - datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', + datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', \ 'ps', 'fs', 'as', None}, optional Specify the unit if a datetime coordinate is used. @@ -5598,12 +5596,14 @@ def pad( self, pad_width: Mapping[Any, int | tuple[int, int]] | None = None, mode: PadModeOptions = "constant", - stat_length: ( - int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None - ) = None, - constant_values: ( - float | tuple[float, float] | Mapping[Any, tuple[float, float]] | None - ) = None, + stat_length: int + | tuple[int, int] + | Mapping[Any, tuple[int, int]] + | None = None, + constant_values: float + | tuple[float, float] + | Mapping[Any, tuple[float, float]] + | None = None, end_values: int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None = None, reflect_type: PadReflectOptions = None, keep_attrs: bool | None = None, @@ -5625,7 +5625,7 @@ def pad( Mapping with the form of {dim: (pad_before, pad_after)} describing the number of values padded along each dimension. {dim: pad} is a shortcut for pad_before = pad_after = pad - mode : {"constant", "edge", "linear_ramp", "maximum", "mean", "median", + mode : {"constant", "edge", "linear_ramp", "maximum", "mean", "median", \ "minimum", "reflect", "symmetric", "wrap"}, default: "constant" How to pad the DataArray (taken from numpy docs): diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 2656fcf2667..e0da6286564 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -2230,7 +2230,7 @@ def to_netcdf( Write ('w') or append ('a') mode. If mode='w', any existing file at this location will be overwritten. If mode='a', existing variables will be overwritten. - format : {"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT",, + format : {"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT", \ "NETCDF3_CLASSIC"}, optional File format for the resulting netCDF file: @@ -3801,7 +3801,7 @@ def interp( New coordinate can be a scalar, array-like or DataArray. If DataArrays are passed as new coordinates, their dimensions are used for the broadcasting. Missing values are skipped. - method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial",, + method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial", \ "barycentric", "krogh", "pchip", "spline", "akima"}, default: "linear" String indicating which method to use for interpolation: @@ -4080,7 +4080,7 @@ def interp_like( Object with an 'indexes' attribute giving a mapping from dimension names to an 1d array-like, which provides coordinates upon which to index the variables in this dataset. Missing values are skipped. - method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial",, + method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial", \ "barycentric", "krogh", "pchip", "spline", "akima"}, default: "linear" String indicating which method to use for interpolation: @@ -5646,7 +5646,7 @@ def merge( overwrite_vars : hashable or iterable of hashable, optional If provided, update variables of these name(s) without checking for conflicts in this dataset. - compat : {"identical", "equals", "broadcast_equals",, + compat : {"identical", "equals", "broadcast_equals", \ "no_conflicts", "override", "minimal"}, default: "no_conflicts" String indicating how to compare variables of the same name for potential conflicts: @@ -5662,7 +5662,7 @@ def merge( - 'override': skip comparing and pick variable from first dataset - 'minimal': drop conflicting coordinates - join : {"outer", "inner", "left", "right", "exact", "override"},, + join : {"outer", "inner", "left", "right", "exact", "override"}, \ default: "outer" Method for joining ``self`` and ``other`` along shared dimensions: @@ -5677,7 +5677,7 @@ def merge( fill_value : scalar or dict-like, optional Value to use for newly missing values. If a dict-like, maps variable names (including coordinates) to fill values. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts",, + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ "override"} or callable, default: "override" A callable or a string indicating how to combine attrs of the objects being merged: @@ -6466,7 +6466,7 @@ def interpolate_na( ---------- dim : Hashable or None, optional Specifies the dimension along which to interpolate. - method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial",, + method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial", \ "barycentric", "krogh", "pchip", "spline", "akima"}, default: "linear" String indicating which method to use for interpolation: @@ -7487,7 +7487,7 @@ def from_dict(cls, d: Mapping[Any, Any]) -> Self: ---------- d : dict-like Mapping with a minimum structure of - ``{"var_0": {"dims": [..], "data": [..]},, + ``{"var_0": {"dims": [..], "data": [..]}, \ ...}`` Returns @@ -8265,7 +8265,7 @@ def differentiate( edge_order: Literal[1, 2] = 1, datetime_unit: DatetimeUnitOptions | None = None, ) -> Self: - """Differentiate with the second order accurate central + """ Differentiate with the second order accurate central differences. .. note:: @@ -8278,7 +8278,7 @@ def differentiate( The coordinate to be used to compute the gradient. edge_order : {1, 2}, default: 1 N-th order accurate differences at the boundaries. - datetime_unit : None or {"Y", "M", "W", "D", "h", "m", "s", "ms",, + datetime_unit : None or {"Y", "M", "W", "D", "h", "m", "s", "ms", \ "us", "ns", "ps", "fs", "as", None}, default: None Unit to compute gradient. Only valid for datetime coordinate. @@ -8346,7 +8346,7 @@ def integrate( ---------- coord : hashable, or sequence of hashable Coordinate(s) used for the integration. - datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns',, + datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', \ 'ps', 'fs', 'as', None}, optional Specify the unit if datetime coordinate is used. @@ -8469,7 +8469,7 @@ def cumulative_integrate( ---------- coord : hashable, or sequence of hashable Coordinate(s) used for the integration. - datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns',, + datetime_unit : {'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', \ 'ps', 'fs', 'as', None}, optional Specify the unit if datetime coordinate is used. @@ -8997,7 +8997,7 @@ def pad( Mapping with the form of {dim: (pad_before, pad_after)} describing the number of values padded along each dimension. {dim: pad} is a shortcut for pad_before = pad_after = pad - mode : {"constant", "edge", "linear_ramp", "maximum", "mean", "median",, + mode : {"constant", "edge", "linear_ramp", "maximum", "mean", "median", \ "minimum", "reflect", "symmetric", "wrap"}, default: "constant" How to pad the DataArray (taken from numpy docs): diff --git a/xarray/core/merge.py b/xarray/core/merge.py index a96922072be..a689620e524 100644 --- a/xarray/core/merge.py +++ b/xarray/core/merge.py @@ -208,7 +208,7 @@ def merge_collected( prioritized : mapping compat : str Type of equality check to use when checking for conflicts. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts",, + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ "override"} or callable, default: "override" A callable or a string indicating how to combine attrs of the objects being merged: @@ -666,7 +666,7 @@ def merge_core( Compatibility checks to use when merging variables. join : {"outer", "inner", "left", "right"}, optional How to combine objects with different indexes. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts",, + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ "override"} or callable, default: "override" How to combine attributes of objects priority_arg : int, optional @@ -762,7 +762,7 @@ def merge( objects : iterable of Dataset or iterable of DataArray or iterable of dict-like Merge together all variables from these objects. If any of them are DataArray objects, they must have a name. - compat : {"identical", "equals", "broadcast_equals", "no_conflicts",, + compat : {"identical", "equals", "broadcast_equals", "no_conflicts", \ "override", "minimal"}, default: "no_conflicts" String indicating how to compare variables of the same name for potential conflicts: @@ -795,7 +795,7 @@ def merge( Value to use for newly missing values. If a dict-like, maps variable names to fill values. Use a data array's name to refer to its values. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts",, + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ "override"} or callable, default: "override" A callable or a string indicating how to combine attrs of the objects being merged: diff --git a/xarray/core/resample.py b/xarray/core/resample.py index c88de3f3de9..3bb158acfdb 100644 --- a/xarray/core/resample.py +++ b/xarray/core/resample.py @@ -145,7 +145,7 @@ def interpolate(self, kind: InterpOptions = "linear") -> T_Xarray: Parameters ---------- - kind : {"linear", "nearest", "zero", "slinear", + kind : {"linear", "nearest", "zero", "slinear", \ "quadratic", "cubic", "polynomial"}, default: "linear" The method used to interpolate. The method should be supported by the scipy interpolator: diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 7d0e72d1833..abb7d71640c 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -1231,12 +1231,14 @@ def pad( self, pad_width: Mapping[Any, int | tuple[int, int]] | None = None, mode: PadModeOptions = "constant", - stat_length: ( - int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None - ) = None, - constant_values: ( - float | tuple[float, float] | Mapping[Any, tuple[float, float]] | None - ) = None, + stat_length: int + | tuple[int, int] + | Mapping[Any, tuple[int, int]] + | None = None, + constant_values: float + | tuple[float, float] + | Mapping[Any, tuple[float, float]] + | None = None, end_values: int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None = None, reflect_type: PadReflectOptions = None, keep_attrs: bool | None = None, @@ -1792,7 +1794,7 @@ def concat( This option is used internally to speed-up groupby operations. If `shortcut` is True, some checks of internal consistency between arrays to concatenate are skipped. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ "override"}, default: "override" String indicating how to combine attrs of the objects being merged: @@ -2959,7 +2961,7 @@ def concat( This option is used internally to speed-up groupby operations. If `shortcut` is True, some checks of internal consistency between arrays to concatenate are skipped. - combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", + combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \ "override"}, default: "override" String indicating how to combine attrs of the objects being merged: From fe1bced33f27b0868f497df3b354d1b7d7431bab Mon Sep 17 00:00:00 2001 From: eschalk Date: Mon, 5 Feb 2024 23:53:05 +0100 Subject: [PATCH 11/18] Fix missing backslash escape --- xarray/core/accessor_str.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 762f21aed4b..a48fbc91faf 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -1008,7 +1008,7 @@ def isspace(self) -> T_DataArray: >>> da = xr.DataArray(["", " ", "\\t", "\\n"], dims="x") >>> da Size: 16B - array(['', ' ', '\t', '\n'], dtype='>> isspace = da.str.isspace() >>> isspace From 7c7214dd7444d15b5180767b3a880f0bf6dab23b Mon Sep 17 00:00:00 2001 From: eschalk Date: Mon, 5 Feb 2024 23:58:59 +0100 Subject: [PATCH 12/18] Fix ellipsis in excess leading to excess last line --- xarray/core/options.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xarray/core/options.py b/xarray/core/options.py index 4b8dd97e51f..25b56b5ef06 100644 --- a/xarray/core/options.py +++ b/xarray/core/options.py @@ -261,7 +261,6 @@ class set_options: * x (x) int64 8kB 0 1 ... 999 Data variables: *empty* - *empty* Or to set global options: From 2049c9e447e7416517282ebd58a0119b6f96f84c Mon Sep 17 00:00:00 2001 From: eschalk Date: Tue, 6 Feb 2024 00:37:05 +0100 Subject: [PATCH 13/18] Update reprs in tests --- xarray/tests/test_dask.py | 12 ++++----- xarray/tests/test_dataarray.py | 22 ++++++++-------- xarray/tests/test_dataset.py | 46 ++++++++++++++++----------------- xarray/tests/test_formatting.py | 6 ++--- xarray/tests/test_sparse.py | 16 ++++++------ xarray/tests/test_variable.py | 2 +- 6 files changed, 52 insertions(+), 52 deletions(-) diff --git a/xarray/tests/test_dask.py b/xarray/tests/test_dask.py index d384d6a07fa..b2d18012fb0 100644 --- a/xarray/tests/test_dask.py +++ b/xarray/tests/test_dask.py @@ -194,7 +194,7 @@ def test_binary_op_bitshift(self) -> None: def test_repr(self): expected = dedent( f"""\ - + Size: 192B {self.lazy_var.data!r}""" ) assert expected == repr(self.lazy_var) @@ -666,10 +666,10 @@ def test_dataarray_repr(self): a = DataArray(data, dims=["x"], coords={"y": ("x", nonindex_coord)}) expected = dedent( f"""\ - + Size: 8B {data!r} Coordinates: - y (x) int64 dask.array + y (x) int64 8B dask.array Dimensions without coordinates: x""" ) assert expected == repr(a) @@ -681,13 +681,13 @@ def test_dataset_repr(self): ds = Dataset(data_vars={"a": ("x", data)}, coords={"y": ("x", nonindex_coord)}) expected = dedent( """\ - + Size: 16B Dimensions: (x: 1) Coordinates: - y (x) int64 dask.array + y (x) int64 8B dask.array Dimensions without coordinates: x Data variables: - a (x) int64 dask.array""" + a (x) int64 8B dask.array""" ) assert expected == repr(ds) assert kernel_call_count == 0 # should not evaluate dask array diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index ab1fc316f77..d3122244737 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -93,12 +93,12 @@ def test_repr(self) -> None: data_array = DataArray(v, coords, name="my_variable") expected = dedent( """\ - + Size: 48B array([[1, 2, 3], [4, 5, 6]]) Coordinates: - * x (x) int64 0 1 2 - other int64 0 + * x (x) int64 24B 0 1 2 + other int64 8B 0 Dimensions without coordinates: time Attributes: foo: bar""" @@ -108,12 +108,12 @@ def test_repr(self) -> None: def test_repr_multiindex(self) -> None: expected = dedent( """\ - + Size: 32B array([0, 1, 2, 3]) Coordinates: - * x (x) object MultiIndex - * level_1 (x) object 'a' 'a' 'b' 'b' - * level_2 (x) int64 1 2 1 2""" + * x (x) object 32B MultiIndex + * level_1 (x) object 32B 'a' 'a' 'b' 'b' + * level_2 (x) int64 32B 1 2 1 2""" ) assert expected == repr(self.mda) @@ -125,13 +125,13 @@ def test_repr_multiindex_long(self) -> None: mda_long = DataArray(list(range(32)), coords={"x": mindex_long}, dims="x") expected = dedent( """\ - + Size: 256B array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]) Coordinates: - * x (x) object MultiIndex - * level_1 (x) object 'a' 'a' 'a' 'a' 'a' 'a' 'a' ... 'd' 'd' 'd' 'd' 'd' 'd' - * level_2 (x) int64 1 2 3 4 5 6 7 8 1 2 3 4 5 6 ... 4 5 6 7 8 1 2 3 4 5 6 7 8""" + * x (x) object 256B MultiIndex + * level_1 (x) object 256B 'a' 'a' 'a' 'a' 'a' 'a' ... 'd' 'd' 'd' 'd' 'd' 'd' + * level_2 (x) int64 256B 1 2 3 4 5 6 7 8 1 2 3 4 ... 5 6 7 8 1 2 3 4 5 6 7 8""" ) assert expected == repr(mda_long) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 77d172f00b8..c6717816dd9 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -289,18 +289,18 @@ def test_repr(self) -> None: # need to insert str dtype at runtime to handle different endianness expected = dedent( """\ - + Size: 2kB Dimensions: (dim2: 9, dim3: 10, time: 20, dim1: 8) Coordinates: - * dim2 (dim2) float64 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 - * dim3 (dim3) %s 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' - * time (time) datetime64[ns] 2000-01-01 2000-01-02 ... 2000-01-20 - numbers (dim3) int64 0 1 2 0 0 1 1 2 2 3 + * dim2 (dim2) float64 72B 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 + * dim3 (dim3) %s 40B 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' + * time (time) datetime64[ns] 160B 2000-01-01 2000-01-02 ... 2000-01-20 + numbers (dim3) int64 80B 0 1 2 0 0 1 1 2 2 3 Dimensions without coordinates: dim1 Data variables: - var1 (dim1, dim2) float64 -1.086 0.9973 0.283 ... 0.1995 0.4684 -0.8312 - var2 (dim1, dim2) float64 1.162 -1.097 -2.123 ... 0.1302 1.267 0.3328 - var3 (dim3, dim1) float64 0.5565 -0.2121 0.4563 ... -0.2452 -0.3616 + var1 (dim1, dim2) float64 576B -1.086 0.9973 0.283 ... 0.4684 -0.8312 + var2 (dim1, dim2) float64 576B 1.162 -1.097 -2.123 ... 1.267 0.3328 + var3 (dim3, dim1) float64 640B 0.5565 -0.2121 0.4563 ... -0.2452 -0.3616 Attributes: foo: bar""" % data["dim3"].dtype @@ -315,7 +315,7 @@ def test_repr(self) -> None: expected = dedent( """\ - + Size: 0B Dimensions: () Data variables: *empty*""" @@ -328,10 +328,10 @@ def test_repr(self) -> None: data = Dataset({"foo": ("x", np.ones(10))}).mean() expected = dedent( """\ - + Size: 8B Dimensions: () Data variables: - foo float64 1.0""" + foo float64 8B 1.0""" ) actual = "\n".join(x.rstrip() for x in repr(data).split("\n")) print(actual) @@ -345,12 +345,12 @@ def test_repr_multiindex(self) -> None: data = create_test_multiindex() expected = dedent( """\ - + Size: 96B Dimensions: (x: 4) Coordinates: - * x (x) object MultiIndex - * level_1 (x) object 'a' 'a' 'b' 'b' - * level_2 (x) int64 1 2 1 2 + * x (x) object 32B MultiIndex + * level_1 (x) object 32B 'a' 'a' 'b' 'b' + * level_2 (x) int64 32B 1 2 1 2 Data variables: *empty*""" ) @@ -366,12 +366,12 @@ def test_repr_multiindex(self) -> None: data = Dataset({}, midx_coords) expected = dedent( """\ - + Size: 96B Dimensions: (x: 4) Coordinates: - * x (x) object MultiIndex - * a_quite_long_level_name (x) object 'a' 'a' 'b' 'b' - * level_2 (x) int64 1 2 1 2 + * x (x) object 32B MultiIndex + * a_quite_long_level_name (x) object 32B 'a' 'a' 'b' 'b' + * level_2 (x) int64 32B 1 2 1 2 Data variables: *empty*""" ) @@ -394,10 +394,10 @@ def test_unicode_data(self) -> None: byteorder = "<" if sys.byteorder == "little" else ">" expected = dedent( """\ - + Size: 12B Dimensions: (foø: 1) Coordinates: - * foø (foø) %cU3 %r + * foø (foø) %cU3 12B %r Data variables: *empty* Attributes: @@ -426,11 +426,11 @@ def __repr__(self): dataset = Dataset({"foo": ("x", Array())}) expected = dedent( """\ - + Size: 16B Dimensions: (x: 2) Dimensions without coordinates: x Data variables: - foo (x) float64 Custom Array""" + foo (x) float64 16B Custom Array""" ) assert expected == repr(dataset) diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index 413ff8e39d4..eba4eec6de2 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -634,7 +634,7 @@ def test_repr_file_collapsed(tmp_path) -> None: actual = repr(arr) expected = dedent( """\ - + Size: 2kB [300 values with dtype=int64] Dimensions without coordinates: test""" ) @@ -645,7 +645,7 @@ def test_repr_file_collapsed(tmp_path) -> None: actual = arr_loaded.__repr__() expected = dedent( """\ - + Size: 2kB 0 1 2 3 4 5 6 7 8 9 10 11 12 ... 288 289 290 291 292 293 294 295 296 297 298 299 Dimensions without coordinates: test""" ) @@ -709,7 +709,7 @@ def test__mapping_repr(display_max_rows, n_vars, n_attr) -> None: ds, col_width=col_width + 1, max_rows=display_max_rows ) expected = f"""\ - + Size: 1kB {dims_start}({dims_values}) Coordinates: ({n_vars}) Data variables: ({n_vars}) diff --git a/xarray/tests/test_sparse.py b/xarray/tests/test_sparse.py index 5b75c10631a..a06d5472ac6 100644 --- a/xarray/tests/test_sparse.py +++ b/xarray/tests/test_sparse.py @@ -297,7 +297,7 @@ def test_bivariate_ufunc(self): def test_repr(self): expected = dedent( """\ - + Size: 288B """ ) assert expected == repr(self.var) @@ -681,10 +681,10 @@ def test_dataarray_repr(self): ) expected = dedent( """\ - + Size: 64B Coordinates: - y (x) int64 + y (x) int64 48B Dimensions without coordinates: x""" ) assert expected == repr(a) @@ -696,13 +696,13 @@ def test_dataset_repr(self): ) expected = dedent( """\ - + Size: 112B Dimensions: (x: 4) Coordinates: - y (x) int64 + y (x) int64 48B Dimensions without coordinates: x Data variables: - a (x) float64 """ + a (x) float64 64B """ ) assert expected == repr(ds) @@ -713,11 +713,11 @@ def test_sparse_dask_dataset_repr(self): ).chunk() expected = dedent( """\ - + Size: 32B Dimensions: (x: 4) Dimensions without coordinates: x Data variables: - a (x) float64 dask.array""" + a (x) float64 32B dask.array""" ) assert expected == repr(ds) diff --git a/xarray/tests/test_variable.py b/xarray/tests/test_variable.py index fb083586415..e15de077900 100644 --- a/xarray/tests/test_variable.py +++ b/xarray/tests/test_variable.py @@ -1230,7 +1230,7 @@ def test_repr(self): v = Variable(["time", "x"], [[1, 2, 3], [4, 5, 6]], {"foo": "bar"}) expected = dedent( """ - + Size: 48B array([[1, 2, 3], [4, 5, 6]]) Attributes: From e98a97d3085e7dc3b1bcb11ac8af012fc1acc1c4 Mon Sep 17 00:00:00 2001 From: eschalk Date: Tue, 6 Feb 2024 00:52:33 +0100 Subject: [PATCH 14/18] Fix tests --- xarray/tests/test_dataarray.py | 4 ++-- xarray/tests/test_dataset.py | 12 ++++++------ xarray/tests/test_formatting.py | 22 +++++++++++----------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index d3122244737..d80a2b0b5b3 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -1445,8 +1445,8 @@ def test_coords(self) -> None: expected_repr = dedent( """\ Coordinates: - * x (x) int64 -1 -2 - * y (y) int64 0 1 2""" + * x (x) int64 16B -1 -2 + * y (y) int64 24B 0 1 2""" ) actual = repr(da.coords) assert expected_repr == actual diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index c6717816dd9..0affee9b5fd 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -883,10 +883,10 @@ def test_coords_properties(self) -> None: expected = dedent( """\ Coordinates: - * x (x) int64 -1 -2 - * y (y) int64 0 1 2 - a (x) int64 4 5 - b int64 -10""" + * x (x) int64 16B -1 -2 + * y (y) int64 24B 0 1 2 + a (x) int64 16B 4 5 + b int64 8B -10""" ) actual = repr(coords) assert expected == actual @@ -1076,8 +1076,8 @@ def test_data_vars_properties(self) -> None: expected = dedent( """\ Data variables: - foo (x) float64 1.0 - bar float64 2.0""" + foo (x) float64 8B 1.0 + bar float64 8B 2.0""" ) actual = repr(ds.data_vars) assert expected == actual diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index eba4eec6de2..a3809d99878 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -316,12 +316,12 @@ def test_diff_array_repr(self) -> None: R array([1, 2], dtype=int64) Differing coordinates: - L * x (x) %cU1 8B 'a' 'b' - R * x (x) %cU1 8B 'a' 'c' + L * x (x) %cU1 8B 'a' 'b' + R * x (x) %cU1 8B 'a' 'c' Coordinates only on the left object: - * y (y) int64 24B 1 2 3 + * y (y) int64 24B 1 2 3 Coordinates only on the right object: - label (x) int64 16B 1 2 + label (x) int64 16B 1 2 Differing attributes: L units: m R units: kg @@ -436,22 +436,22 @@ def test_diff_dataset_repr(self) -> None: Differing dimensions: (x: 2, y: 3) != (x: 2) Differing coordinates: - L * x (x) %cU1 8B 'a' 'b' + L * x (x) %cU1 8B 'a' 'b' Differing variable attributes: foo: bar - R * x (x) %cU1 8B 'a' 'c' + R * x (x) %cU1 8B 'a' 'c' Differing variable attributes: source: 0 foo: baz Coordinates only on the left object: - * y (y) int64 24B 1 2 3 + * y (y) int64 24B 1 2 3 Coordinates only on the right object: - label (x) int64 16B 1 2 + label (x) int64 16B 1 2 Differing data variables: - L var1 (x, y) int64 48B 1 2 3 4 5 6 - R var1 (x) int64 16B 1 2 + L var1 (x, y) int64 48B 1 2 3 4 5 6 + R var1 (x) int64 16B 1 2 Data variables only on the left object: - var2 (x) int64 16B 3 4 + var2 (x) int64 16B 3 4 Differing attributes: L title: mytitle R title: newtitle From e7248258bd1b5ab82fd0fa6ebe7bf901eed08cca Mon Sep 17 00:00:00 2001 From: eschalk Date: Tue, 6 Feb 2024 20:56:57 +0100 Subject: [PATCH 15/18] Try windows specific expected outputs --- xarray/tests/test_dataarray.py | 74 +++++++++++++++++++++++++++++++++ xarray/tests/test_formatting.py | 22 +++++++--- 2 files changed, 90 insertions(+), 6 deletions(-) diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index d80a2b0b5b3..737fa08b79e 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -71,6 +71,8 @@ pytest.mark.filterwarnings("error:All-NaN (slice|axis) encountered"), ] +ON_WINDOWS = sys.platform == "win32" + class TestDataArray: @pytest.fixture(autouse=True) @@ -87,6 +89,10 @@ def setup(self): ) self.mda = DataArray([0, 1, 2, 3], coords={"x": self.mindex}, dims="x") + @pytest.mark.skipif( + ON_WINDOWS, + reason="Default numpy's dtypes vary according to OS", + ) def test_repr(self) -> None: v = Variable(["time", "x"], [[1, 2, 3], [4, 5, 6]], {"foo": "bar"}) coords = {"x": np.arange(3, dtype=np.int64), "other": np.int64(0)} @@ -105,6 +111,32 @@ def test_repr(self) -> None: ) assert expected == repr(data_array) + @pytest.mark.skipif( + not ON_WINDOWS, + reason="Default numpy's dtypes vary according to OS", + ) + def test_repr_windows(self) -> None: + v = Variable(["time", "x"], [[1, 2, 3], [4, 5, 6]], {"foo": "bar"}) + coords = {"x": np.arange(3, dtype=np.int64), "other": np.int64(0)} + data_array = DataArray(v, coords, name="my_variable") + expected = dedent( + """\ + Size: 24B + array([[1, 2, 3], + [4, 5, 6]]) + Coordinates: + * x (x) int32 12B 0 1 2 + other int32 4B 0 + Dimensions without coordinates: time + Attributes: + foo: bar""" + ) + assert expected == repr(data_array) + + @pytest.mark.skipif( + ON_WINDOWS, + reason="Default numpy's dtypes vary according to OS", + ) def test_repr_multiindex(self) -> None: expected = dedent( """\ @@ -117,6 +149,26 @@ def test_repr_multiindex(self) -> None: ) assert expected == repr(self.mda) + @pytest.mark.skipif( + not ON_WINDOWS, + reason="Default numpy's dtypes vary according to OS", + ) + def test_repr_multiindex_windows(self) -> None: + expected = dedent( + """\ + Size: 16B + array([0, 1, 2, 3]) + Coordinates: + * x (x) object 16B MultiIndex + * level_1 (x) object 16B 'a' 'a' 'b' 'b' + * level_2 (x) int64 16B 1 2 1 2""" + ) + assert expected == repr(self.mda) + + @pytest.mark.skipif( + ON_WINDOWS, + reason="Default numpy's dtypes vary according to OS", + ) def test_repr_multiindex_long(self) -> None: mindex_long = pd.MultiIndex.from_product( [["a", "b", "c", "d"], [1, 2, 3, 4, 5, 6, 7, 8]], @@ -135,6 +187,28 @@ def test_repr_multiindex_long(self) -> None: ) assert expected == repr(mda_long) + @pytest.mark.skipif( + not ON_WINDOWS, + reason="Default numpy's dtypes vary according to OS", + ) + def test_repr_multiindex_long_windows(self) -> None: + mindex_long = pd.MultiIndex.from_product( + [["a", "b", "c", "d"], [1, 2, 3, 4, 5, 6, 7, 8]], + names=("level_1", "level_2"), + ) + mda_long = DataArray(list(range(32)), coords={"x": mindex_long}, dims="x") + expected = dedent( + """\ + Size: 128B + array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]) + Coordinates: + * x (x) object 128B MultiIndex + * level_1 (x) object 128B 'a' 'a' 'a' 'a' 'a' 'a' ... 'd' 'd' 'd' 'd' 'd' 'd' + * level_2 (x) int64 128B 1 2 3 4 5 6 7 8 1 2 3 4 ... 5 6 7 8 1 2 3 4 5 6 7 8""" + ) + assert expected == repr(mda_long) + def test_properties(self) -> None: assert_equal(self.dv.variable, self.v) assert_array_equal(self.dv.values, self.v.values) diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index a3809d99878..a5312abb1a1 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -12,6 +12,8 @@ from xarray.core import formatting from xarray.tests import requires_cftime, requires_dask, requires_netCDF4 +ON_WINDOWS = sys.platform == "win32" + class TestFormatting: def test_get_indexer_at_least_n_items(self) -> None: @@ -470,12 +472,20 @@ def test_array_repr(self) -> None: # Test repr function behaves correctly: actual = formatting.array_repr(ds_12) - expected = dedent( - """\ - Size: 8B - array([0]) - Dimensions without coordinates: test""" - ) + if ON_WINDOWS: + expected = dedent( + """\ + Size: 8B + array([0]) + Dimensions without coordinates: test""" + ) + else: + expected = dedent( + """\ + Size: 4B + array([0]) + Dimensions without coordinates: test""" + ) assert actual == expected From e2db82a6d2a322e6ed18ebb0cb2bd696458b540c Mon Sep 17 00:00:00 2001 From: eschalk Date: Tue, 6 Feb 2024 21:05:34 +0100 Subject: [PATCH 16/18] Conditional Windows testing --- xarray/tests/test_formatting.py | 28 +++++++++++++++++++--------- xarray/tests/test_variable.py | 30 ++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index a5312abb1a1..1ee6c86d064 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -475,14 +475,14 @@ def test_array_repr(self) -> None: if ON_WINDOWS: expected = dedent( """\ - Size: 8B + Size: 4B array([0]) Dimensions without coordinates: test""" ) else: expected = dedent( """\ - Size: 4B + Size: 8B array([0]) Dimensions without coordinates: test""" ) @@ -499,12 +499,21 @@ def test_array_repr(self) -> None: with xr.set_options(display_expand_data=False): actual = formatting.array_repr(ds[(1, 2)]) - expected = dedent( - """\ - Size: 8B - 0 - Dimensions without coordinates: test""" - ) + if ON_WINDOWS: + expected = dedent( + """\ + Size: 4B + 0 + Dimensions without coordinates: test""" + ) + + else: + expected = dedent( + """\ + Size: 8B + 0 + Dimensions without coordinates: test""" + ) assert actual == expected @@ -718,8 +727,9 @@ def test__mapping_repr(display_max_rows, n_vars, n_attr) -> None: dims_values = formatting.dim_summary_limited( ds, col_width=col_width + 1, max_rows=display_max_rows ) + expected_size = "640B" if ON_WINDOWS else "1kB" expected = f"""\ - Size: 1kB + Size: {expected_size} {dims_start}({dims_values}) Coordinates: ({n_vars}) Data variables: ({n_vars}) diff --git a/xarray/tests/test_variable.py b/xarray/tests/test_variable.py index e15de077900..f2754d26483 100644 --- a/xarray/tests/test_variable.py +++ b/xarray/tests/test_variable.py @@ -1,5 +1,6 @@ from __future__ import annotations +import sys import warnings from abc import ABC from copy import copy, deepcopy @@ -58,6 +59,8 @@ [{"x": (3, 1), "z": 2}, ((3, 1), (0, 0), (2, 2))], ] +ON_WINDOWS = sys.platform == "win32" + @pytest.fixture def var(): @@ -1228,15 +1231,26 @@ def test_as_variable(self): def test_repr(self): v = Variable(["time", "x"], [[1, 2, 3], [4, 5, 6]], {"foo": "bar"}) - expected = dedent( + if ON_WINDOWS: + expected = dedent( + """ + Size: 24B + array([[1, 2, 3], + [4, 5, 6]]) + Attributes: + foo: bar """ - Size: 48B - array([[1, 2, 3], - [4, 5, 6]]) - Attributes: - foo: bar - """ - ).strip() + ).strip() + else: + expected = dedent( + """ + Size: 48B + array([[1, 2, 3], + [4, 5, 6]]) + Attributes: + foo: bar + """ + ).strip() assert expected == repr(v) def test_repr_lazy_data(self): From 0f93f9fce061efdb318cd5e890e40f8814d6f14a Mon Sep 17 00:00:00 2001 From: eschalk Date: Tue, 6 Feb 2024 21:17:02 +0100 Subject: [PATCH 17/18] Fix indent --- xarray/tests/test_variable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_variable.py b/xarray/tests/test_variable.py index f2754d26483..08990f87b13 100644 --- a/xarray/tests/test_variable.py +++ b/xarray/tests/test_variable.py @@ -1236,7 +1236,7 @@ def test_repr(self): """ Size: 24B array([[1, 2, 3], - [4, 5, 6]]) + [4, 5, 6]]) Attributes: foo: bar """ @@ -1246,7 +1246,7 @@ def test_repr(self): """ Size: 48B array([[1, 2, 3], - [4, 5, 6]]) + [4, 5, 6]]) Attributes: foo: bar """ From 9ae49dca6162176558e3261be26a38abc7394393 Mon Sep 17 00:00:00 2001 From: eschalk Date: Tue, 6 Feb 2024 21:51:55 +0100 Subject: [PATCH 18/18] Flaky test + fix windows --- xarray/tests/test_backends.py | 1 + xarray/tests/test_dataarray.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 0863974f449..4115edc0278 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -4490,6 +4490,7 @@ def test_open_multi_dataset(self) -> None: ) as actual: assert_identical(expected, actual) + @pytest.mark.xfail(reason="Flaky test. Very open to contributions on fixing this") def test_dask_roundtrip(self) -> None: with create_tmp_file() as tmp: data = create_test_data() diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 468010ffff1..6cdae79ca3f 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -125,8 +125,8 @@ def test_repr_windows(self) -> None: array([[1, 2, 3], [4, 5, 6]]) Coordinates: - * x (x) int32 12B 0 1 2 - other int32 4B 0 + * x (x) int64 24B 0 1 2 + other int64 8B 0 Dimensions without coordinates: time Attributes: foo: bar""" @@ -159,9 +159,9 @@ def test_repr_multiindex_windows(self) -> None: Size: 16B array([0, 1, 2, 3]) Coordinates: - * x (x) object 16B MultiIndex - * level_1 (x) object 16B 'a' 'a' 'b' 'b' - * level_2 (x) int64 16B 1 2 1 2""" + * x (x) object 32B MultiIndex + * level_1 (x) object 32B 'a' 'a' 'b' 'b' + * level_2 (x) int64 32B 1 2 1 2""" ) assert expected == repr(self.mda) @@ -203,9 +203,9 @@ def test_repr_multiindex_long_windows(self) -> None: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]) Coordinates: - * x (x) object 128B MultiIndex - * level_1 (x) object 128B 'a' 'a' 'a' 'a' 'a' 'a' ... 'd' 'd' 'd' 'd' 'd' 'd' - * level_2 (x) int64 128B 1 2 3 4 5 6 7 8 1 2 3 4 ... 5 6 7 8 1 2 3 4 5 6 7 8""" + * x (x) object 256B MultiIndex + * level_1 (x) object 256B 'a' 'a' 'a' 'a' 'a' 'a' ... 'd' 'd' 'd' 'd' 'd' 'd' + * level_2 (x) int64 256B 1 2 3 4 5 6 7 8 1 2 3 4 ... 5 6 7 8 1 2 3 4 5 6 7 8""" ) assert expected == repr(mda_long)