From 4d94bcf9f530f539eac725d8cf4c95c82306f5ef Mon Sep 17 00:00:00 2001 From: Alexis Jeandet Date: Wed, 17 Apr 2024 14:13:35 +0200 Subject: [PATCH] Always check if a cache entry isn't None before slicing it Signed-off-by: Alexis Jeandet --- speasy/core/cache/_providers_caches.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/speasy/core/cache/_providers_caches.py b/speasy/core/cache/_providers_caches.py index 691160b8..f1103c7d 100644 --- a/speasy/core/cache/_providers_caches.py +++ b/speasy/core/cache/_providers_caches.py @@ -180,8 +180,10 @@ def wrapped(wrapped_self, product, start_time, stop_time, **kwargs): if len(data_chunks): if len(data_chunks) == 1: return data_chunks[0][dt_range.start_time:dt_range.stop_time].copy() - data_chunks[0] = data_chunks[0][dt_range.start_time:] - data_chunks[-1] = data_chunks[-1][:dt_range.stop_time] + if data_chunks[0] is not None: + data_chunks[0] = data_chunks[0][dt_range.start_time:] + if data_chunks[-1] is not None: + data_chunks[-1] = data_chunks[-1][:dt_range.stop_time] return merge_variables(data_chunks)[dt_range.start_time:dt_range.stop_time] return None @@ -273,8 +275,12 @@ def wrapped(wrapped_self, product, start_time, stop_time, **kwargs): if len(data_chunks): if len(data_chunks) == 1: - return data_chunks[0][dt_range.start_time:dt_range.stop_time].copy() - data_chunks[0] = data_chunks[0][dt_range.start_time:] + if data_chunks[0] is not None: + return data_chunks[0][dt_range.start_time:dt_range.stop_time].copy() + else: + return None + if data_chunks[0] is not None: + data_chunks[0] = data_chunks[0][dt_range.start_time:] if data_chunks[-1] is not None: data_chunks[-1] = data_chunks[-1][:dt_range.stop_time] return merge_variables(data_chunks)[dt_range.start_time:dt_range.stop_time]