home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 819897789

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
819897789 MDU6SXNzdWU4MTk4OTc3ODk= 4983 Date missing in datetime accessor 43613877 closed 0     4 2021-03-02T10:52:00Z 2021-03-16T10:00:23Z 2021-03-16T10:00:23Z CONTRIBUTOR      

What happened: I wonder if there is a reason, why there is no date attribute in the datetime accessor.

What you expected to happen: As the time attribute is supported I would expect the same for the date attribute

Minimal Complete Verifiable Example:

```python import xarray as xr import pandas as pd time_coord = pd.date_range("2020-01-01","2020-01-03", freq="12H") da = xr.DataArray([1,2,3,4,5], dims=["time"], coords={'time': time_coord})

print(da.time.dt.time)

<xarray.DataArray 'time' (time: 5)>

array([datetime.time(0, 0), datetime.time(12, 0), datetime.time(0, 0),

datetime.time(12, 0), datetime.time(0, 0)], dtype=object)

Coordinates:

* time (time) datetime64[ns] 2020-01-01 2020-01-01T12:00:00 ... 2020-01-03

print(da.time.dt.date)

---------------------------------------------------------------------------

AttributeError Traceback (most recent call last)

<ipython-input-42-13741f407661> in <module>

----> 1 da.time.dt.date

AttributeError: 'DatetimeAccessor' object has no attribute 'date'

```

Suggestion: A simple addition of date = Properties._tslib_field_accessor( "date", "Date corresponding to datetimes", object ) in core/accessor_dt.py should do the trick. Happy to do a PR.

Anything else we need to know?:

Environment:

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: None python: 3.8.6 | packaged by conda-forge | (default, Oct 7 2020, 19:08:05) [GCC 7.5.0] python-bits: 64 OS: Linux OS-release: 2.6.32-754.33.1.el6.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.6 libnetcdf: 4.7.4 xarray: 0.17.0 pandas: 1.2.1 numpy: 1.20.0 scipy: 1.6.0 netCDF4: 1.5.5.1 pydap: None h5netcdf: None h5py: None Nio: None zarr: 2.6.1 cftime: 1.4.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2021.02.0 distributed: 2021.02.0 matplotlib: 3.3.4 cartopy: 0.18.0 seaborn: 0.11.1 numbagg: None pint: 0.16.1 setuptools: 49.6.0.post20210108 pip: 21.0.1 conda: None pytest: None IPython: 7.20.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/4983/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

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