issues: 365438396
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
365438396 | MDU6SXNzdWUzNjU0MzgzOTY= | 2450 | da.loc[date[0]] brings up two instead of one | 41115380 | closed | 0 | 17 | 2018-10-01T12:29:31Z | 2018-10-02T20:38:38Z | 2018-10-02T20:38:37Z | NONE | Problem descriptionMy dataset has lots of days, with data for two times for each day: midnight and midday (12am and 12pm). With date[0], I am trying to retrieve only the midnight data from the first day; with date[1], the midday data from the same day; date[3] the midnight data from the next day, etc. Now I'm writing this, I'm not sure I've posted this in the right place so please let me know if I haven't. Code Sample 1: this gives data for midnight and midday (time: 2)```python from datetime import datetime, timedelta start = datetime(1979, 1, 1) date = [start.strftime('%Y%m%d')] a = first_dataset.loc[date[0]] print(a) <xarray.DataArray (time: 2, latitude: 241, longitude: 480)> array([[[ #there are numbers here, cut out for ease of reading ]]]) Coordinates: * longitude (longitude) float32 0.0 0.75 1.5 2.25 3.0 3.75 4.5 5.25 6.0 ... * latitude (latitude) float32 90.0 89.25 88.5 87.75 87.0 86.25 85.5 ... * time (time) datetime64[ns] 1979-01-01 1979-01-01 T12:00:00 #as you can see here, for midnight the time is just 1979-01-01 instead of 1979-01-01 00:00:00, which I think might be causingsome confusion in my code``` Code Sample 2: try adding hour to the date```python from datetime import datetime, timedelta start = datetime(1979, 1, 1) date = [start.strftime('%Y%m%d%H')] #this what I changed a = first_dataset.loc[date[0]] print(a) Traceback (most recent call last): File "pandas/index.pyx", line 589, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11661) File "pandas/src/hashtable_class_helper.pxi", line 404, in pandas.hashtable.Int64HashTable.get_item (pandas/hashtable.c:8543) TypeError: an integer is required During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/pandas/indexes/base.py", line 2134, in get_loc return self._engine.get_loc(key) File "pandas/index.pyx", line 553, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11829) File "pandas/index.pyx", line 591, in pandas.index.DatetimeEngine.get_loc (pandas/index.c:11735) File "pandas/index.pyx", line 597, in pandas.index.DatetimeEngine._date_check_type (pandas/index.c:11899) KeyError: '1979010100' ``` Expected Output```python a = first_dataset.loc[date[0]] print(a) <xarray.DataArray (time: 1, latitude: 241, longitude: 480)> array([[[ #there are numbers here, cut out for ease of reading ]]]) Coordinates: * longitude (longitude) float32 0.0 0.75 1.5 2.25 3.0 3.75 4.5 5.25 6.0 ... * latitude (latitude) float32 90.0 89.25 88.5 87.75 87.0 86.25 85.5 ... * time (time) datetime64[ns] 1979-01-01 ``` |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/2450/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |