Skip to content

Commit

Permalink
Add a simple nbytes representation in DataArrays and Dataset repr
Browse files Browse the repository at this point in the history
… (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
  • Loading branch information
etienneschalk authored Feb 7, 2024
1 parent 0eb6658 commit db680b0
Show file tree
Hide file tree
Showing 33 changed files with 2,561 additions and 2,188 deletions.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ v2024.02.0 (unreleased)
New Features
~~~~~~~~~~~~

- Added a simple `nbytes` representation in DataArrays and Dataset `repr`.
(:issue:`8690`, :pull:`8702`).
By `Etienne Schalk <https://github.com/etienneschalk>`_.
- 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 <https://github.com/mathause>`_.
Expand Down
6 changes: 3 additions & 3 deletions xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,12 +1431,12 @@ def save_mfdataset(
... coords={"time": pd.date_range("2010-01-01", freq="ME", periods=48)},
... )
>>> ds
<xarray.Dataset>
<xarray.Dataset> 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)
Expand Down
12 changes: 6 additions & 6 deletions xarray/coding/cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,30 +383,30 @@ def _partial_date_slice(self, resolution, parsed):
... dims=["time"],
... )
>>> da.sel(time="2001-01-01")
<xarray.DataArray (time: 1)>
<xarray.DataArray (time: 1)> 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")
<xarray.DataArray ()>
<xarray.DataArray ()> 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")
<xarray.DataArray (time: 1)>
<xarray.DataArray (time: 1)> 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)

Expand Down
Loading

0 comments on commit db680b0

Please sign in to comment.