home / github

Menu
  • GraphQL API
  • Search all tables

issues

Table actions
  • GraphQL API for issues

4 rows where repo = 13221727, type = "issue" and user = 2405019 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: comments, created_at (date), updated_at (date), closed_at (date)

type 1

  • issue · 4 ✖

state 1

  • closed 4

repo 1

  • xarray · 4 ✖
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
1044693438 I_kwDOAMm_X84-RMG- 5937 DataArray.dt.seconds returns incorrect value for negative `timedelta64[ns]` leifdenby 2405019 closed 0     4 2021-11-04T12:05:24Z 2023-11-10T00:39:17Z 2023-11-10T00:39:17Z CONTRIBUTOR      

What happened:

For a negative timedelta64[ns] of 42 nanoseconds DataArray.dt.seconds returned a non-zero value (the returned value was 86399). When I pass in a positive 42 nanosecond timedelta64[ns] with the the TimeDeltaAccessor correctly returns zero. I would have expected both assertions in the example below to have passed, but the second fails. This seems to be a general issue with negative timedelta64[ns].

bash <xarray.DataArray 'seconds' (dim_0: 1)> array([0]) Dimensions without coordinates: dim_0 <xarray.DataArray 'seconds' (dim_0: 1)> array([86399]) Dimensions without coordinates: dim_0 Traceback (most recent call last): File "bug_dt_seconds.py", line 15, in <module> assert da.dt.seconds == 0 AssertionError

What you expected to happen: bash <xarray.DataArray 'seconds' (dim_0: 1)> array([0]) Dimensions without coordinates: dim_0 <xarray.DataArray 'seconds' (dim_0: 1)> array([0]) Dimensions without coordinates: dim_0

Minimal Complete Verifiable Example:

```python

coding: utf-8

import xarray as xr import numpy as np

number of nanoseconds

value = 42

da = xr.DataArray([np.timedelta64(value, "ns")]) print(da.dt.seconds) assert da.dt.seconds == 0

da = xr.DataArray([np.timedelta64(-value, "ns")]) print(da.dt.seconds) assert da.dt.seconds == 0 ```

Anything else we need to know?:

I've narrowed this down to the call to pd.Series(values.ravel()) in xarray.core.accessor_dt._access_through_series:

python ipdb> pd.Series(values.ravel()) 0 -1 days +23:59:59.999999958 dtype: timedelta64[ns]

I think the issue arises because pandas turns the numpy timedelta64 into a "minus one day plus a time". This actually does have a number of "seconds" in it, but the "total_seconds" has the expected value:

python ipdb> pd.Series(values.ravel()).dt.total_seconds() 0 -4.200000e-08 dtype: float64

Which would correctly round to zero.

I don't think the issue is in pandas, although the output from pandas is counter-intuitive:

python ipdb> pd.Series(values.ravel()).dt.seconds 0 86399 dtype: int64

Maybe we should handle this as a special case by taking the absolute value before passing the values to pandas (and then applying the original sign again afterwards)?

Environment:

Output of <tt>xr.show_versions()</tt> ``` INSTALLED VERSIONS ------------------ commit: None python: 3.7.7 (default, May 6 2020, 04:59:01) [Clang 4.0.1 (tags/RELEASE_401/final)] python-bits: 64 OS: Darwin OS-release: 19.6.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: en_GB.UTF-8 LANG: None LOCALE: ('en_GB', 'UTF-8') libhdf5: 1.10.4 libnetcdf: 4.6.2 xarray: 0.18.2 pandas: 1.3.4 numpy: 1.19.1 scipy: 1.5.0 netCDF4: 1.4.2 pydap: installed h5netcdf: None h5py: 2.9.0 Nio: None zarr: 2.10.1 cftime: 1.5.1.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: 1.3.2 dask: 2021.09.1 distributed: 2021.09.1 matplotlib: 3.2.2 cartopy: 0.18.0 seaborn: 0.10.1 numbagg: None fsspec: 2021.06.1 cupy: None pint: 0.18 sparse: None setuptools: 46.4.0.post20200518 pip: 21.1.2 conda: None pytest: 6.0.1 IPython: 7.16.1 sphinx: None ```
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/5937/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed xarray 13221727 issue
798676024 MDU6SXNzdWU3OTg2NzYwMjQ= 4854 `bounds_error=True` ignored in 1D interpolation leifdenby 2405019 closed 0     0 2021-02-01T20:17:34Z 2021-02-10T21:42:06Z 2021-02-10T21:42:06Z CONTRIBUTOR      

What happened:

Attempted to interpolate outside coordinate range while passing bounds_error=True through kwargs dictionary (which internally gets passed to scipy.interpolate.interp1d). Instead if interp function raising a ValueError nans are returned.

What you expected to happen:

I expected a ValueError exception to be raised when I've passed in the kwargs bounds_error=True.

Minimal Complete Verifiable Example:

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

da = xr.DataArray( np.sin(0.3 * np.arange(12).reshape(4, 3)), [("time", np.arange(4)), ("space", [0.1, 0.2, 0.3])], )

this should return nans, as the default is to fill with nans

da.interp(time=3.5)

<xarray.DataArray (space: 3)> array([nan, nan, nan]) Coordinates: * space (space) float64 0.1 0.2 0.3 time float64 3.5

this should raise ValueError, but bounds_error is ignored

da.interp(time=3.5, kwargs=dict(bounds_error=True))

<xarray.DataArray (space: 3)> array([nan, nan, nan]) Coordinates: * space (space) float64 0.1 0.2 0.3 time float64 3.5

```

Anything else we need to know?:

I've made a pull-request to fix the issue

Environment:

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: None python: 2.7.15.final.0 python-bits: 64 OS: Linux OS-release: 3.10.0-957.27.2.el7.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: None.None xarray: 0.10.7 pandas: 0.23.0 numpy: 1.14.3 scipy: 1.1.0 netCDF4: None h5netcdf: None h5py: 2.7.1 Nio: None zarr: None bottleneck: 1.2.1 cyordereddict: None dask: 0.17.5 distributed: 1.21.8 matplotlib: None cartopy: None seaborn: None setuptools: 39.1.0 pip: 10.0.1 conda: 4.6.4 pytest: 3.5.1 IPython: 5.7.0 sphinx: 1.7.4
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/4854/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed xarray 13221727 issue
672662079 MDU6SXNzdWU2NzI2NjIwNzk= 4306 Indexing datetime broken with pandas 1.1.0 leifdenby 2405019 closed 0     2 2020-08-04T09:50:59Z 2020-08-04T09:54:46Z 2020-08-04T09:54:46Z CONTRIBUTOR      

Code below works with pandas<=1.0.5 and is broken with the most recent version (pandas==1.1.0) independent of xarray version (tried 0.16.0 and 0.15.0)

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

dates = pd.date_range("2000-01-01", periods=5) ds = xr.Dataset(coords=dict(dates=dates)) ds['v'] = ("dates"), np.arange(ds.dates.count())

ds.sel(dates=ds.dates.values[2]) ```

The `.sel` operation produces a KeyError in `pandas/core/indexes/datetimes.py`:
Traceback (most recent call last):
  File "datetime_problem.py", line 11, in <module>
    ds.sel(dates=ds.dates.values[2])
  File "/Users/leifdenby/miniconda3/envs/lagtraj/lib/python3.8/site-packages/xarray/core/dataset.py", line 2101, in sel
    pos_indexers, new_indexes = remap_label_indexers(
  File "/Users/leifdenby/miniconda3/envs/lagtraj/lib/python3.8/site-packages/xarray/core/coordinates.py", line 396, in remap_label_indexers
    pos_indexers, new_indexes = indexing.remap_label_indexers(
  File "/Users/leifdenby/miniconda3/envs/lagtraj/lib/python3.8/site-packages/xarray/core/indexing.py", line 270, in remap_label_indexers
    idxr, new_idx = convert_label_indexer(index, label, dim, method, tolerance)
  File "/Users/leifdenby/miniconda3/envs/lagtraj/lib/python3.8/site-packages/xarray/core/indexing.py", line 189, in convert_label_indexer
    indexer = index.get_loc(
  File "/Users/leifdenby/miniconda3/envs/lagtraj/lib/python3.8/site-packages/pandas/core/indexes/datetimes.py", line 622, in get_loc
    raise KeyError(key)
KeyError: 946857600000000000

Environment:

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: None python: 3.8.5 | packaged by conda-forge | (default, Jul 24 2020, 01:06:20) [Clang 10.0.1 ] python-bits: 64 OS: Darwin OS-release: 18.0.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: en_GB.UTF-8 LANG: None LOCALE: en_GB.UTF-8 libhdf5: 1.10.5 libnetcdf: 4.6.3 xarray: 0.16.0 pandas: 1.1.0 numpy: 1.19.1 scipy: 1.5.2 netCDF4: 1.5.4 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.2.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2.22.0 distributed: None matplotlib: 3.3.0 cartopy: None seaborn: None numbagg: None pint: None setuptools: 49.2.0.post20200712 pip: 20.1.1 conda: None pytest: 6.0.1 IPython: 7.16.1 sphinx: None

Apologies if this is a know issue. I tried to work out whether this is an issue with pandas or xarray (I assume it is with pandas), but couldn't find the right piece of code. Happy to fix the issue if someone could show me what needs to change.

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/4306/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed xarray 13221727 issue
607678694 MDU6SXNzdWU2MDc2Nzg2OTQ= 4010 Issue indexing by xarray's own time values + offset leifdenby 2405019 closed 0     2 2020-04-27T16:20:34Z 2020-04-28T11:03:06Z 2020-04-28T08:20:16Z CONTRIBUTOR      

I'm struggling to work out how to index by a xarray time value + an offset (either created using np.timedelta64 or datetime.timedelta). I read through https://github.com/pydata/xarray/issues/1240 and https://github.com/pydata/xarray/issues/1240 because they appear related, but I'm not sure how to correctly achieve this.

MCVE Code Sample

```python import xarray as xr import numpy as np import datetime as dt

now = dt.datetime.now() dt_array = xr.DataArray( range(10), dims=('time', ), coords=dict(time=[now + dt.timedelta(seconds=i) for i in range(10)]) )

this works

dt_array.loc[dt_array.time.min():dt_array.time.max()].count() == 10

this fails, only the first value is returned (adding

the time delta appears to have no effect)

dt_array.loc[dt_array.time.min():dt_array.time.min() + np.timedelta64(seconds=4)].count() == 4

this fails, an exception is raised when trying to add

a datetime.timedelta to the xarray value

dt_array.loc[dt_array.time.min():dt_array.time.max() + dt.timedelta(seconds=4)].count() == 4

also fails, I got the impression from issue #1240

that .loc[...] should work for indexing too, but just to double-check

dt_array.sel(time=slice(dt_array.time.min(), dt_array.time.min() + np.timedelta64(seconds=4))).count() == 4

fails, showing that adding a time increment has no effect

dt_array.time.min() + np.timedelta64(seconds=10) != dt_array.time.min() ```

Expected Output

Where I am indexing by the minimum time plus a np.timedelta64 offset of 4 seconds I would expect a DataArray of length 4 to be return. It would be nice if it was possible to add an increment with a native datetime.timedelta object.

Problem Description

I can't work out how to correctly add an increment to a time value in an xarray DataArray. It would be nice if one of the above approaches worked. Or maybe if I'm missing something obvious I could add an example to the documentation on datetime-indexing?

Versions

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: None python: 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 19:16:44) [GCC 7.3.0] python-bits: 64 OS: Linux OS-release: 3.10.0-957.27.2.el7.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8 libhdf5: 1.10.1 libnetcdf: 4.5.0 xarray: 0.15.1 pandas: 0.25.3 numpy: 1.15.4 scipy: 1.1.0 netCDF4: 1.4.0 pydap: None h5netcdf: 0.7.4 h5py: 2.10.0 Nio: None zarr: None cftime: 1.0.2.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: 2.2.0 bottleneck: None dask: 0.20.0 distributed: 1.24.0 matplotlib: 2.2.3 cartopy: 0.16.0 seaborn: 0.9.0 numbagg: None setuptools: 46.1.3 pip: 10.0.1 conda: None pytest: 5.3.2 IPython: 7.1.1 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/4010/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed xarray 13221727 issue

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issues] (
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [number] INTEGER,
   [title] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [state] TEXT,
   [locked] INTEGER,
   [assignee] INTEGER REFERENCES [users]([id]),
   [milestone] INTEGER REFERENCES [milestones]([id]),
   [comments] INTEGER,
   [created_at] TEXT,
   [updated_at] TEXT,
   [closed_at] TEXT,
   [author_association] TEXT,
   [active_lock_reason] TEXT,
   [draft] INTEGER,
   [pull_request] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [state_reason] TEXT,
   [repo] INTEGER REFERENCES [repos]([id]),
   [type] TEXT
);
CREATE INDEX [idx_issues_repo]
    ON [issues] ([repo]);
CREATE INDEX [idx_issues_milestone]
    ON [issues] ([milestone]);
CREATE INDEX [idx_issues_assignee]
    ON [issues] ([assignee]);
CREATE INDEX [idx_issues_user]
    ON [issues] ([user]);
Powered by Datasette · Queries took 98.552ms · About: xarray-datasette