Skip to content

Commit 3877047

Browse files
authored
Fix/ Allow empty TimeSeries (#1359)
* removed the assert preventing TimeSeries to be empty, updated the associated test and the docstring * added support for plotting empty TimeSeries
1 parent ec78594 commit 3877047

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

darts/tests/test_logging.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_timeseries_constructor_error_log(self):
6363
(
6464
"darts.timeseries",
6565
"ERROR",
66-
"ValueError: The time series array must not be empty.",
66+
"ValueError: TimeSeries require DataArray of dimensionality 3 (('time', 'component', 'sample')).",
6767
)
6868
)
6969

darts/timeseries.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
- Contain numeric types only
2323
- Have distinct components/columns names
2424
- Have a well defined frequency (for ``DateTimeIndex``)
25-
- Be non-empty
2625
- Have static covariates consistent with their components, or no static covariates
2726
- Have a hierarchy consistent with their components, or no hierarchy
2827
@@ -86,7 +85,6 @@ def __init__(self, xa: xr.DataArray):
8685
"TimeSeries.from_times_and_values(), etc...).",
8786
logger,
8887
)
89-
raise_if_not(xa.size > 0, "The time series array must not be empty.", logger)
9088
raise_if_not(
9189
len(xa.shape) == 3,
9290
f"TimeSeries require DataArray of dimensionality 3 ({DIMS}).",
@@ -3230,6 +3228,15 @@ def plot(
32303228

32313229
if central_series.shape[0] > 1:
32323230
p = central_series.plot(*args, **kwargs)
3231+
# empty TimeSeries
3232+
elif central_series.shape[0] == 0:
3233+
p = plt.plot(
3234+
[],
3235+
[],
3236+
*args,
3237+
**kwargs,
3238+
)
3239+
plt.xlabel(self.time_index.name)
32333240
else:
32343241
p = plt.plot(
32353242
[self.start_time()],

0 commit comments

Comments
 (0)