Skip to content

Commit 9f5d78e

Browse files
committed
added option to raise warning when no match is found, see TUW-GEO#152
1 parent 79a3bb7 commit 9f5d78e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/pytesmo/temporal_matching.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ def matching(reference, *args, **kwargs):
177177

178178
def temporal_collocation(reference, other, window, method="nearest",
179179
return_index=False, return_distance=False,
180-
dropduplicates=False, dropna=False, flag=None,
181-
use_invalid=False):
180+
dropduplicates=False, dropna=False, checkna=False,
181+
flag=None, use_invalid=False):
182182
"""
183183
Temporally collocates values to reference.
184184
@@ -218,7 +218,11 @@ def temporal_collocation(reference, other, window, method="nearest",
218218
dropna : bool, optional
219219
Whether to drop NaNs from the resulting dataframe (arising for example
220220
from duplicates with ``duplicates_nan=True`` or from missing values).
221-
Default is ``False``
221+
Default is ``False``.
222+
checkna: bool, optional
223+
Whether to check if only NaNs are returned (i.e. no match has been
224+
found). If set to ``True``, raises a ``UserWarning`` in case no match
225+
has been found. Default is ``False``.
222226
flag : np.ndarray, str or None, optional
223227
Flag column as array or name of the flag column in `other`. If this is
224228
given, the column will be interpreted as validity indicator. Any
@@ -307,6 +311,9 @@ def collocate(df):
307311

308312
# postprocessing
309313
# --------------
314+
if checkna:
315+
if np.any(collocated.isnull().apply(np.all)):
316+
warnings.warn("No match has been found")
310317
if dropna:
311318
collocated.dropna(inplace=True)
312319

0 commit comments

Comments
 (0)