issues: 1006413760
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1006413760 | I_kwDOAMm_X847_KfA | 5815 | Inconsistent dropping of `DatetimeIndex.freq` attribute from `DataArray`s index. | 4806678 | closed | 0 | 7 | 2021-09-24T12:28:27Z | 2023-08-23T13:41:17Z | 2023-08-23T13:41:17Z | CONTRIBUTOR | What happened: Indexing on What you expected to happen: I would expect the Minimal Complete Verifiable Example: ```python import xarray as xr import pandas as pd import numpy as np from pandas.tseries.frequencies import to_offset freq = to_offset('MS') time_index = pd.DatetimeIndex([pd.Timestamp('20130101') + i * freq for i in range(10)]) xa_orig = xr.DataArray(np.random.randn(10), dims=('time'), coords={'time': time_index}) xa_copy = xa_orig.copy() xa_sorted = xa_orig.sortby('time') Set freq on all DataArrays:xa_orig.get_index('time').freq = freq xa_copy.get_index('time').freq = freq xa_sorted.get_index('time').freq = freq Print to confirm the freq is set correctly:print(xa_orig.get_index('time').freq) print(xa_copy.get_index('time').freq) print(xa_sorted.get_index('time').freq) ``` Output (OK - as expected) ```
Now, try some indexing using Output (Not as expected:
Now, try the same using Output (Not as expected:
Anything else we need to know?: Environment: Output of <tt>xr.show_versions()</tt>INSTALLED VERSIONS ------------------ commit: None python: 3.8.5 (default, Sep 4 2020, 02:22:02) [Clang 10.0.0 ] python-bits: 64 OS: Darwin OS-release: 20.5.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: None LOCALE: (None, 'UTF-8') libhdf5: None libnetcdf: None xarray: 0.19.0 pandas: 1.2.3 numpy: 1.19.5 scipy: 1.6.2 netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: None nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.4.1 cartopy: None seaborn: None numbagg: None pint: None setuptools: 49.6.0.post20200814 pip: 21.1.3 conda: None pytest: None IPython: 7.22.0 sphinx: 3.2.1 |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/5815/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |