Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰[BUG]: time averaging loses the time coordinate informations #179

Open
ChenggongWang opened this issue Mar 4, 2024 · 0 comments
Open
Labels
? - Needs Triage Need team to review and classify bug Something isn't working

Comments

@ChenggongWang
Copy link
Contributor

Version

source - main

On which installation method(s) does this occur?

Source

Describe the issue

This bug is caused by code here and can be reproduced by following code.

import pandas as pd
import numpy as np
time = pd.date_range("2000-01-01", freq="h", periods=365 * 24)
ds = xr.Dataset({"foo": ("time", np.arange(365 * 24)), "time": time})
print('raw')
print(ds.time)
print('corrected resample')
print(ds.resample(time='1ME').mean(dim="time", keep_attrs=True, skipna=False).time)
print('current resample loses the time coordinate information')
print(ds.resample(time='1ME').mean(dim="time", keep_attrs=True, skipna=False, keepdims=True).time)

output

raw
 Size: 70kB
array(['2000-01-01T00:00:00.000000000', '2000-01-01T01:00:00.000000000',
       '2000-01-01T02:00:00.000000000', ..., '2000-12-30T21:00:00.000000000',
       '2000-12-30T22:00:00.000000000', '2000-12-30T23:00:00.000000000'],
      dtype='datetime64[ns]')
Coordinates:
  * time     (time) datetime64[ns] 70kB 2000-01-01 ... 2000-12-30T23:00:00
corrected resample
 Size: 96B
array(['2000-01-31T00:00:00.000000000', '2000-02-29T00:00:00.000000000',
       '2000-03-31T00:00:00.000000000', '2000-04-30T00:00:00.000000000',
       '2000-05-31T00:00:00.000000000', '2000-06-30T00:00:00.000000000',
       '2000-07-31T00:00:00.000000000', '2000-08-31T00:00:00.000000000',
       '2000-09-30T00:00:00.000000000', '2000-10-31T00:00:00.000000000',
       '2000-11-30T00:00:00.000000000', '2000-12-31T00:00:00.000000000'],
      dtype='datetime64[ns]')
Coordinates:
  * time     (time) datetime64[ns] 96B 2000-01-31 2000-02-29 ... 2000-12-31
current resample loses the time coordinate information
 Size: 96B
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])
Dimensions without coordinates: time

Suggestion: keepdims=True should be removed.

Environment details

No response

@ChenggongWang ChenggongWang added ? - Needs Triage Need team to review and classify bug Something isn't working labels Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
? - Needs Triage Need team to review and classify bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant