Skip to content

Commit db680b0

Browse files
Add a simple nbytes representation in DataArrays and Dataset repr (opt-in) (#8702)
* Add nbytes to repr * Disable by default * What's new * Specify dtype explictly as Windows seems to default on int32 * Use int16 * PR comments: Removed global option + size format in repr header * Remove width justified * Remove problematic backslashes * pytest-accept * Revert "Remove problematic backslashes" This reverts commit 85f6ee4. * Fix missing backslash escape * Fix ellipsis in excess leading to excess last line * Update reprs in tests * Fix tests * Try windows specific expected outputs * Conditional Windows testing * Fix indent * Flaky test + fix windows
1 parent 0eb6658 commit db680b0

33 files changed

+2561
-2188
lines changed

doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ v2024.02.0 (unreleased)
2323
New Features
2424
~~~~~~~~~~~~
2525

26+
- Added a simple `nbytes` representation in DataArrays and Dataset `repr`.
27+
(:issue:`8690`, :pull:`8702`).
28+
By `Etienne Schalk <https://github.com/etienneschalk>`_.
2629
- Allow negative frequency strings (e.g. ``"-1YE"``). These strings are for example used
2730
in :py:func:`date_range`, and :py:func:`cftime_range` (:pull:`8651`).
2831
By `Mathias Hauser <https://github.com/mathause>`_.

xarray/backends/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,12 +1431,12 @@ def save_mfdataset(
14311431
... coords={"time": pd.date_range("2010-01-01", freq="ME", periods=48)},
14321432
... )
14331433
>>> ds
1434-
<xarray.Dataset>
1434+
<xarray.Dataset> Size: 768B
14351435
Dimensions: (time: 48)
14361436
Coordinates:
1437-
* time (time) datetime64[ns] 2010-01-31 2010-02-28 ... 2013-12-31
1437+
* time (time) datetime64[ns] 384B 2010-01-31 2010-02-28 ... 2013-12-31
14381438
Data variables:
1439-
a (time) float64 0.0 0.02128 0.04255 0.06383 ... 0.9574 0.9787 1.0
1439+
a (time) float64 384B 0.0 0.02128 0.04255 ... 0.9574 0.9787 1.0
14401440
>>> years, datasets = zip(*ds.groupby("time.year"))
14411441
>>> paths = [f"{y}.nc" for y in years]
14421442
>>> xr.save_mfdataset(datasets, paths)

xarray/coding/cftimeindex.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,30 +383,30 @@ def _partial_date_slice(self, resolution, parsed):
383383
... dims=["time"],
384384
... )
385385
>>> da.sel(time="2001-01-01")
386-
<xarray.DataArray (time: 1)>
386+
<xarray.DataArray (time: 1)> Size: 8B
387387
array([1])
388388
Coordinates:
389-
* time (time) object 2001-01-01 00:00:00
389+
* time (time) object 8B 2001-01-01 00:00:00
390390
>>> da = xr.DataArray(
391391
... [1, 2],
392392
... coords=[[pd.Timestamp(2001, 1, 1), pd.Timestamp(2001, 2, 1)]],
393393
... dims=["time"],
394394
... )
395395
>>> da.sel(time="2001-01-01")
396-
<xarray.DataArray ()>
396+
<xarray.DataArray ()> Size: 8B
397397
array(1)
398398
Coordinates:
399-
time datetime64[ns] 2001-01-01
399+
time datetime64[ns] 8B 2001-01-01
400400
>>> da = xr.DataArray(
401401
... [1, 2],
402402
... coords=[[pd.Timestamp(2001, 1, 1, 1), pd.Timestamp(2001, 2, 1)]],
403403
... dims=["time"],
404404
... )
405405
>>> da.sel(time="2001-01-01")
406-
<xarray.DataArray (time: 1)>
406+
<xarray.DataArray (time: 1)> Size: 8B
407407
array([1])
408408
Coordinates:
409-
* time (time) datetime64[ns] 2001-01-01T01:00:00
409+
* time (time) datetime64[ns] 8B 2001-01-01T01:00:00
410410
"""
411411
start, end = _parsed_string_to_bounds(self.date_type, resolution, parsed)
412412

0 commit comments

Comments
 (0)