implement the inline repr#22
Conversation
Codecov Report
@@ Coverage Diff @@
## master #22 +/- ##
==========================================
- Coverage 87.25% 86.16% -1.09%
==========================================
Files 9 11 +2
Lines 706 795 +89
==========================================
+ Hits 616 685 +69
- Misses 90 110 +20
Continue to review full report at Codecov.
|
|
thinking about this some more, this doesn't work for anything other than However, as we nest deeper (e.g. If I'm simply missing something we have that discussion here, otherwise I guess we should open a issue on |
|
Yes, I agree that I think a cascading series of
Assuming all this, then each layer of the nesting will reduce the max length of the inline repr string available to the layers below it, until a layer reaches a reasonable minimum where it "gives up". At least that's the natural design that I inferred from the simple All that being said, it might still be good to bring up on xarray's end since this is a more general issue with inline reprs of nested duck arrays, with nothing pint-specific other than it being the motivating use-case. |
|
Also, as far as tests go, I'd think a unit test for this could be as simple as assert q._repr_inline_(40) == "expected 40 character inline string repr..."for a couple combinations of dtypes, shapes, and max widths. I'd see no need for integration tests making sure the final repr is as expected (since that's more on xarray's end). |
|
not sure how to test that we forward to duck arrays properly, but that's something that depends on pydata/xarray#4324. So I guess this is ready for review? |
|
My only suggestion is vendoring Otherwise looks good! |
|
Vendoring |
|
👍 for vendoring. I suspect you can make use a much simplified version of the associated helper functions, because pandas is really only used for datetime formatting. |
|
well, although it doesn't really make sense, this works: In [5]: import pint
...: import pandas as pd
...:
...: ureg = pint.UnitRegistry()
...: ureg.Quantity(pd.date_range("2010-01-01", periods=10).to_numpy(), "m")
Out[5]:
array(['2010-01-01T00:00:00.000000000', '2010-01-02T00:00:00.000000000',
'2010-01-03T00:00:00.000000000', '2010-01-04T00:00:00.000000000',
'2010-01-05T00:00:00.000000000', '2010-01-06T00:00:00.000000000',
'2010-01-07T00:00:00.000000000', '2010-01-08T00:00:00.000000000',
'2010-01-09T00:00:00.000000000', '2010-01-10T00:00:00.000000000'],
dtype='datetime64[ns]') <Unit('meter')>if we disregard that, vendoring would indeed be much easier. |
|
with the vendoring the coverage decreases, but I think that's fine as long as we keep it in sync with the |
|
Looks good now with the vendoring. I did catch one more thing on another go-through (sorry about that). Hopefully this won't matter in practice, but the pathological case where |
|
I switched to using the vendored |
Seems okay to me based on the existing behavior as you mentioned. If it becomes a problem, it can always be adjusted later. |
As discussed in hgrecco/pint#1133, this monkeypatches the
_repr_inline_method introduced in pydata/xarray#4248 ontopint.Quantity, resulting in:However, this uses
xarray.core.formatting.format_array_flatwhich is not public API (maybe it should be?).Also, no tests, yet, because I don't know how to best check a
repr.