home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 686461572

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
686461572 MDU6SXNzdWU2ODY0NjE1NzI= 4378 Plotting when Interval coordinate is timedelta-based 500246 open 0     2 2020-08-26T16:36:27Z 2022-04-18T21:55:15Z   CONTRIBUTOR      

Is your feature request related to a problem? Please describe.

The xarray plotting interface supports coordinates containing pandas.Interval iff those intervals contain numbers. It fails when those intervals contain pandas.Timedelta:

```python import numpy as np import pandas as pd import xarray as xr

da = xr.DataArray( np.arange(10), dims=("x",), coords={"x": [pd.Interval(i, i+1) for i in range(10)]}) da.plot() # works

da = xr.DataArray( np.arange(10), dims=("x",), coords={"x": [pd.Interval( d-pd.Timestamp("2000-01-01"), d-pd.Timestamp("2000-01-01")+pd.Timedelta("1H")) for d in pd.date_range("2000-01-01", "2000-01-02", 10)]}) da.plot() # fails ```

The latter fails with:

Traceback (most recent call last): File "mwe82.py", line 18, in <module> da.plot() # fails File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/plot/plot.py", line 446, in __call__ return plot(self._da, **kwargs) File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/plot/plot.py", line 200, in plot return plotfunc(darray, **kwargs) File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/plot/plot.py", line 302, in line _ensure_plottable(xplt_val, yplt_val) File "/data/gholl/miniconda3/envs/py38/lib/python3.8/site-packages/xarray/plot/utils.py", line 551, in _ensure_plottable raise TypeError( TypeError: Plotting requires coordinates to be numeric or dates of type np.datetime64, datetime.datetime, cftime.datetime or pd.Interval.

This error message is somewhat confusing, because the coordinates are "dates of type (...) pd.Interval", but perhaps a timedelta is not considered a date.

Describe the solution you'd like

I would like that I can use the xarray plotting interface for any pandas.Interval coordinate, including pandas.Timestamp and pandas.Timedelta.

Describe alternatives you've considered

I'll "manually" calculate the midpoints and use those as a timedelta coordinate instead.

Additional context

It seems that regular timedeltas aren't really supported either, although they don't cause an error message, they rather produce incorrect results. There's probably a related issue somewhere, but I can't find it now.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/4378/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 2 rows from issue in issue_comments
Powered by Datasette · Queries took 78.046ms · About: xarray-datasette