From 5773275cb0ad53acf5996e450fd8e0626fbdbbe0 Mon Sep 17 00:00:00 2001 From: twsearle <14909402+twsearle@users.noreply.github.com> Date: Fri, 7 Feb 2020 18:24:59 +0000 Subject: [PATCH 1/2] Add _natargmax function Calculate arg max when an array contains `NaT`. Blocker for upgrading to numpy 1.18. --- forest/satellite.py | 13 +++++++++++-- requirements.txt | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/forest/satellite.py b/forest/satellite.py index 7a136322a..3626aebaf 100644 --- a/forest/satellite.py +++ b/forest/satellite.py @@ -12,6 +12,15 @@ from forest.exceptions import FileNotFound, IndexNotFound +MIN_DATETIME64 = np.datetime64('0001-01-01T00:00:00.000000') + + +def _natargmax(arr): + """ Find the arg max when an array contains NaT's""" + no_nats = np.where(np.isnat(arr), MIN_DATETIME64, arr) + return np.argmax(no_nats) + + class EIDA50(object): def __init__(self, pattern): self.locator = Locator(pattern) @@ -86,7 +95,7 @@ def find_file_index(self, paths, user_date): raise FileNotFound(msg) before_dates = np.ma.array( dates, mask=mask, dtype='datetime64[s]') - return np.ma.argmax(before_dates) + return _natargmax(before_dates.filled()) @staticmethod def find_index(times, time, length): @@ -99,7 +108,7 @@ def find_index(times, time, length): if valid_times.mask.all(): msg = "{}: not found".format(time) raise IndexNotFound(msg) - return np.ma.argmax(valid_times) + return _natargmax(valid_times.filled()) @staticmethod def parse_date(path): diff --git a/requirements.txt b/requirements.txt index 52f9c8f84..7ec27b7f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,4 @@ intake intake-esm pygrib libwebp=1.0.2 # Pin to prevent Travis issue -numpy=1.17.* xarray From 9a283adf1afc771045dd6fc1c643f7cd89e6a698 Mon Sep 17 00:00:00 2001 From: twsearle <14909402+twsearle@users.noreply.github.com> Date: Fri, 7 Feb 2020 18:29:30 +0000 Subject: [PATCH 2/2] Increment version number for fix --- forest/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forest/__init__.py b/forest/__init__.py index f7e89c327..898797746 100644 --- a/forest/__init__.py +++ b/forest/__init__.py @@ -25,7 +25,7 @@ .. automodule:: forest.presets """ -__version__ = '0.7.1' +__version__ = '0.7.2' from .config import * from . import (