home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 919798222

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
919798222 MDU6SXNzdWU5MTk3OTgyMjI= 5466 `DataArray.sortby()` discards `freq` component of `DatetimeIndex` 4806678 open 0     0 2021-06-13T13:22:04Z 2021-06-13T13:22:20Z   CONTRIBUTOR      

What happened:

Calling sortby() on a DataArray indexed with a pd.DatetimeIndex discards the underlying freq component of the pd.DatetimeIndex.

What you expected to happen:

The freq component should probably be kept.

Minimal Complete Verifiable Example:

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

ar = xr.DataArray(np.random.randn(4, 2), dims=('time', 'component'), coords={'time': pd.date_range('20130101', '20130104'), 'component': ['a', 'b']})

print(ar.get_index('time'))

ar_sorted = ar.sortby('time')

print(ar_sorted.get_index('time')) ```

Output for the above snippet (note how the freq becomes None): DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04'], dtype='datetime64[ns]', name='time', freq='D') DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04'], dtype='datetime64[ns]', name='time', freq=None)

Anything else we need to know?:

Environment:

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: None python: 3.8.10 (default, May 19 2021, 11:01:55) [Clang 10.0.0 ] python-bits: 64 OS: Darwin OS-release: 20.3.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: None LOCALE: (None, 'UTF-8') libhdf5: 1.10.6 libnetcdf: 4.7.4 xarray: 0.18.2 pandas: 1.2.3 numpy: 1.19.5 scipy: 1.6.2 netCDF4: 1.5.6 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.5.0 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: 1.3.2 dask: 2021.05.1 distributed: 2021.05.1 matplotlib: 3.4.1 cartopy: None seaborn: None numbagg: None pint: None setuptools: 52.0.0.post20210125 pip: 21.1.1 conda: None pytest: None IPython: 7.22.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/5466/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

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