Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added test for timezone, closes #150 #212

Merged
merged 2 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions src/pytesmo/temporal_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ def df_match(reference, *args, **kwds):
dropduplicates : boolean
Drop duplicated temporal matched (default: False)
asym_window: string, optional
``<=`` stands for using a smaller and equal only for the left/smaller side of the window comparison
``>=`` stands for using a larger and equal only for the right/larger side of the window comparison
``<=`` stands for using a smaller and equal only for the left/smaller
side of the window comparison, ``>=`` stands for using a larger and
equal only for the right/larger side of the window comparison.
The default is to use <= and >= for both sides of the search window

Returns
Expand Down Expand Up @@ -99,14 +100,18 @@ def df_match(reference, *args, **kwds):
if asym_window == "<=":
# this means that only distance in the interval [distance[ are
# taken
valid_dist = ((arg_matched['distance'] >= 0.0) & (arg_matched['distance'] <= window)) | (
(arg_matched['distance'] <= 0.0) & (arg_matched['distance'] > -window))
valid_dist = (((arg_matched['distance'] >= 0.0)
& (arg_matched['distance'] <= window))
| ((arg_matched['distance'] <= 0.0)
& (arg_matched['distance'] > -window)))
invalid_dist = ~valid_dist
if asym_window == ">=":
# this means that only distance in the interval ]distance] are
# taken
valid_dist = ((arg_matched['distance'] >= 0.0) & (arg_matched['distance'] < window)) | (
(arg_matched['distance'] <= 0.0) & (arg_matched['distance'] >= -window))
valid_dist = (((arg_matched['distance'] >= 0.0)
& (arg_matched['distance'] < window))
| ((arg_matched['distance'] <= 0.0)
& (arg_matched['distance'] >= -window)))
invalid_dist = ~valid_dist
arg_matched.loc[invalid_dist] = np.nan

Expand Down Expand Up @@ -147,8 +152,8 @@ def matching(reference, *args, **kwargs):
Returns
-------
temporal_match : pandas.DataFrame
containing the index of the reference Series and a column for each of the
other input Series
containing the index of the reference Series and a column for each of
the other input Series
"""
warnings.warn(
"'pytesmo.temporal_matching.matching' is deprecated. Use"
Expand All @@ -172,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 @@ -213,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 @@ -256,7 +265,6 @@ def temporal_collocation(reference, other, window, method="nearest",
else:
has_invalid = False


# preprocessing
# ------------
if ref_dr.tz is None:
Expand Down Expand Up @@ -303,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
Loading