2
2
import pandas as pd
3
3
import pytest
4
4
import xarray as xr
5
- from packaging .version import Version
6
5
7
6
import mesmer .core .utils
8
7
9
8
10
9
def make_dummy_yearly_data (freq , calendar = "standard" ):
10
+
11
+ # NOTE: "YM" is a made-up "Year-Middle" freq string
11
12
if freq == "YM" :
12
- freq = "AS-JUL" if Version (pd .__version__ ) < Version ("2.2" ) else "YS-JUL"
13
- time = xr .date_range (
14
- start = "2000" , periods = 5 , freq = freq , calendar = calendar
15
- ) + pd .Timedelta ("14d" )
13
+ time = xr .date_range (start = "2000" , periods = 5 , freq = "YS-JUL" , calendar = calendar )
14
+ time = time + pd .Timedelta ("14d" )
16
15
else :
17
16
time = xr .date_range (start = "2000" , periods = 5 , freq = freq , calendar = calendar )
18
17
@@ -21,31 +20,25 @@ def make_dummy_yearly_data(freq, calendar="standard"):
21
20
22
21
23
22
def make_dummy_monthly_data (freq , calendar = "standard" ):
23
+
24
+ start = "2000-01"
25
+ periods = 5 * 12
26
+
27
+ # NOTE: "MM" is a made-up "Month-Middle" freq string
24
28
if freq == "MM" :
25
- time = time = xr .date_range (
26
- start = "2000" , periods = 5 * 12 , freq = "MS" , calendar = calendar
27
- ) + pd .Timedelta ("14d" )
29
+ time = xr .date_range (start = start , periods = periods , freq = "MS" , calendar = calendar )
30
+ time = time + pd .Timedelta ("14d" )
28
31
else :
29
- time = xr .date_range (
30
- start = "2000-01" , periods = 5 * 12 , freq = freq , calendar = calendar
31
- )
32
+ time = xr .date_range (start = start , periods = periods , freq = freq , calendar = calendar )
32
33
33
- data = xr .DataArray (np .ones ( 5 * 12 ), dims = ("time" ), coords = {"time" : time })
34
+ data = xr .DataArray (np .arange ( periods ), dims = ("time" ), coords = {"time" : time })
34
35
return data
35
36
36
37
37
38
@pytest .mark .parametrize ("freq_y" , ["YM" , "YS" , "YE" , "YS-JUL" , "YS-NOV" ])
38
39
@pytest .mark .parametrize ("freq_m" , ["MM" , "MS" , "ME" ])
39
40
@pytest .mark .parametrize ("calendar" , ["standard" , "gregorian" , "365_day" ])
40
41
def test_upsample_yearly_data (freq_y , freq_m , calendar ):
41
- if Version (pd .__version__ ) < Version ("2.2" ):
42
- if freq_y == "YE" :
43
- freq_y = freq_y .replace ("YE" , "A" )
44
- elif "YS" in freq_y :
45
- freq_y = freq_y .replace ("YS" , "AS" )
46
-
47
- if freq_m == "ME" :
48
- freq_m = freq_m .replace ("ME" , "M" )
49
42
50
43
yearly_data = make_dummy_yearly_data (freq_y , calendar = calendar )
51
44
monthly_data = make_dummy_monthly_data (freq_m , calendar = calendar )
@@ -295,10 +288,6 @@ def _get_time(*args, **kwargs):
295
288
calendar = kwargs .pop ("calendar" , "standard" )
296
289
freq = kwargs .pop ("freq" , None )
297
290
298
- # translate freq strings
299
- if freq and Version (xr .__version__ ) < Version ("2024.02" ):
300
- freq = freq .replace ("YE" , "A" ).replace ("ME" , "M" )
301
-
302
291
time = xr .date_range (* args , calendar = calendar , freq = freq , ** kwargs )
303
292
304
293
return xr .DataArray (time , dims = "time" )
0 commit comments