Skip to content

Commit

Permalink
added option to raise warning when no match is found, see TUW-GEO#152
Browse files Browse the repository at this point in the history
  • Loading branch information
s-scherrer committed Feb 12, 2021
1 parent 79a3bb7 commit 9f5d78e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/pytesmo/temporal_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def matching(reference, *args, **kwargs):

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

# postprocessing
# --------------
if checkna:
if np.any(collocated.isnull().apply(np.all)):
warnings.warn("No match has been found")
if dropna:
collocated.dropna(inplace=True)

Expand Down

0 comments on commit 9f5d78e

Please sign in to comment.