File tree Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -679,7 +679,6 @@ def _del_name_attr(self, name: str) -> None:
679
679
@overload
680
680
def __getitem__ (self , key : Hashable | int ) -> DataArray : ...
681
681
682
- # Mapping is Iterable
683
682
@overload
684
683
def __getitem__ (self , key : Iterable [Hashable ]) -> "Dataset" : ...
685
684
Original file line number Diff line number Diff line change 3
3
from pathlib import Path
4
4
from datetime import datetime , timedelta
5
5
from typing import Any , Sequence
6
+ import warnings
6
7
7
8
import numpy as np
8
9
import pandas as pd
@@ -188,13 +189,21 @@ def read(
188
189
sel_time_step_str = None
189
190
time_steps = None
190
191
if time is not None :
191
- _ , time_steps = _valid_timesteps (dfs .FileInfo , time )
192
+ if isinstance (time , slice ) and isinstance (time .start , str ):
193
+ return ds .sel (time = time )
194
+ else :
195
+ _ , time_steps = _valid_timesteps (dfs .FileInfo , time )
192
196
193
197
if time_steps :
194
198
ds = ds .isel (time = time_steps )
195
199
196
200
if sel_time_step_str :
197
201
parts = sel_time_step_str .split ("," )
202
+ if len (parts ) > 0 :
203
+ warnings .warn (
204
+ f'Comma separated time slicing is deprecated use read(time=slice("{ parts [0 ]} ", "{ parts [1 ]} ")) instead.' ,
205
+ FutureWarning ,
206
+ )
198
207
if len (parts ) == 1 :
199
208
parts .append (parts [0 ]) # end=start
200
209
@@ -204,7 +213,8 @@ def read(
204
213
sel = slice (parts [0 ], None ) # start only
205
214
else :
206
215
sel = slice (parts [0 ], parts [1 ])
207
- ds = ds [sel ] # type: ignore
216
+
217
+ return ds .sel (time = sel )
208
218
209
219
return ds
210
220
Original file line number Diff line number Diff line change @@ -517,8 +517,10 @@ def test_read_non_eq_dfs0_temporal_subset():
517
517
dfs0file = r"tests/testdata/da_diagnostic.dfs0"
518
518
519
519
dfs = Dfs0 (dfs0file )
520
- # TODO should this syntax be supported?
521
- ds = dfs .read (time = "2017-10-27 01:00,2017-10-27 02:00" )
520
+
521
+ # deprecated
522
+ with pytest .warns (FutureWarning , match = "time=slice" ):
523
+ ds = dfs .read (time = "2017-10-27 01:00,2017-10-27 02:00" )
522
524
523
525
assert len (ds .time ) == 7
524
526
You can’t perform that action at this time.
0 commit comments