-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow customizing the inline repr of a duck array #4248
Conversation
Looks great to me. I'm not sure the naming convention: is a single |
I think |
exactly, that's where the name came from. Also, if consistency with the functions in |
if I remember correctly, this was accepted in this week's community meeting. Should this be merged, then? |
LGTM! A test wouldn't go amiss but fine to keep moving given the size of the change imo Thank you @keewis ! |
tests are a good point, and I guess this should also be documented somewhere. Any ideas where that could be? Internals? |
"internals" sounds good to me. It could also go in the future NEP-18 wrapping section. |
I put it into internals for now, together with a small paragraph about the requirements on duck arrays, but this should definitely be extended and moved somewhere more visible – maybe a I also added a test, but it feels a bit strange to compare the result with the return value of a direct call to the object's |
should be ready for review again |
Perfect! Thanks for adding to the docs! |
Thanks @keewis
I think this is a great idea! |
In certain situations (e.g. when printing the collapsed preview of | ||
variables of a ``Dataset``), xarray will display the repr of a `duck array`_ | ||
in a single line, truncating it to a certain number of characters. If that | ||
would drop too much information, the `duck array`_ may define a | ||
``_repr_inline_`` method that takes ``max_width`` (number of characters) as an | ||
argument: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to add examples of what should and should not be included in _repr_inline_
.
In particular, shape
and dtype
should not be included because xarray already adds those in a standard way.
For examples of what good _inline_repr_
look like, we could show examples of the output for dask and sparse.
* 'master' of github.com:pydata/xarray: (260 commits) Increase support window of all dependencies (pydata#4296) Implement interp for interpolating between chunks of data (dask) (pydata#4155) Add @mathause to current core developers. (pydata#4335) install sphinx-autosummary-accessors from conda-forge (pydata#4332) Use sphinx-accessors-autosummary (pydata#4323) ndrolling fixes (pydata#4329) DOC: fix typo argmin -> argmax in DataArray.argmax docstring (pydata#4327) pin sphinx to 3.1(pydata#4326) nd-rolling (pydata#4219) Implicit dask import 4164 (pydata#4318) allow customizing the inline repr of a duck array (pydata#4248) silence the known docs CI issues (pydata#4316) enh: fixed pydata#4302 (pydata#4315) Remove all unused and warn-raising methods from AbstractDataStore (pydata#4310) Fix map_blocks example (pydata#4305) Fix docstring for missing_dims argument to isel methods (pydata#4298) Support for PyCharm remote deployment (pydata#4299) Update map_blocks and map_overlap docstrings (pydata#4303) Lazily load resource files (pydata#4297) warn about the removal of the ufuncs (pydata#4268) ...
* upstream/master: (34 commits) Fix bug in computing means of cftime.datetime arrays (pydata#4344) fix some str accessor inconsistencies (pydata#4339) pin matplotlib in ci/requirements/doc.yml (pydata#4340) Clarify drop_vars return value. (pydata#4244) Support explicitly setting a dimension order with to_dataframe() (pydata#4333) Increase support window of all dependencies (pydata#4296) Implement interp for interpolating between chunks of data (dask) (pydata#4155) Add @mathause to current core developers. (pydata#4335) install sphinx-autosummary-accessors from conda-forge (pydata#4332) Use sphinx-accessors-autosummary (pydata#4323) ndrolling fixes (pydata#4329) DOC: fix typo argmin -> argmax in DataArray.argmax docstring (pydata#4327) pin sphinx to 3.1(pydata#4326) nd-rolling (pydata#4219) Implicit dask import 4164 (pydata#4318) allow customizing the inline repr of a duck array (pydata#4248) silence the known docs CI issues (pydata#4316) enh: fixed pydata#4302 (pydata#4315) Remove all unused and warn-raising methods from AbstractDataStore (pydata#4310) Fix map_blocks example (pydata#4305) ...
* upstream/master: (40 commits) Fix bug in computing means of cftime.datetime arrays (pydata#4344) fix some str accessor inconsistencies (pydata#4339) pin matplotlib in ci/requirements/doc.yml (pydata#4340) Clarify drop_vars return value. (pydata#4244) Support explicitly setting a dimension order with to_dataframe() (pydata#4333) Increase support window of all dependencies (pydata#4296) Implement interp for interpolating between chunks of data (dask) (pydata#4155) Add @mathause to current core developers. (pydata#4335) install sphinx-autosummary-accessors from conda-forge (pydata#4332) Use sphinx-accessors-autosummary (pydata#4323) ndrolling fixes (pydata#4329) DOC: fix typo argmin -> argmax in DataArray.argmax docstring (pydata#4327) pin sphinx to 3.1(pydata#4326) nd-rolling (pydata#4219) Implicit dask import 4164 (pydata#4318) allow customizing the inline repr of a duck array (pydata#4248) silence the known docs CI issues (pydata#4316) enh: fixed pydata#4302 (pydata#4315) Remove all unused and warn-raising methods from AbstractDataStore (pydata#4310) Fix map_blocks example (pydata#4305) ...
This calls the duck array's
_repr_short_
(does not have to be that name, might also be_repr_inline_
or something else) if it exists, which can make e.g.pint.Quantity
's inline repr a lot more useful. We might also be able to use that to get rid of ourinline_dask_repr
andinline_sparse_repr
functions by pushing that upstream (or by monkeypatching).isort . && black . && mypy . && flake8
whats-new.rst
api.rst