mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-09 11:19:23 +08:00
MAINT: Fix warnings from numpy on NaT comparison.
This commit is contained in:
@@ -17,8 +17,8 @@ from numpy import (
|
||||
empty,
|
||||
flatnonzero,
|
||||
hstack,
|
||||
isnan,
|
||||
nan,
|
||||
timedelta64,
|
||||
vectorize,
|
||||
where
|
||||
)
|
||||
@@ -287,6 +287,28 @@ def rolling_window(array, length):
|
||||
|
||||
# Sentinel value that isn't NaT.
|
||||
_notNaT = make_datetime64D(0)
|
||||
iNaT = NaTns.view(int64_dtype)
|
||||
assert iNaT == NaTD.view(int64_dtype), "iNaTns != iNaTD"
|
||||
|
||||
|
||||
def isnat(obj):
|
||||
"""
|
||||
Check if a value is np.NaT.
|
||||
"""
|
||||
if obj.dtype.kind not in ('m', 'M'):
|
||||
raise ValueError("%s is not a numpy datetime or timedelta")
|
||||
return obj.view(int64_dtype) == iNaT
|
||||
|
||||
|
||||
def is_missing(data, missing_value):
|
||||
"""
|
||||
Generic is_missing function that handles NaN and NaT.
|
||||
"""
|
||||
if is_float(data) and isnan(missing_value):
|
||||
return isnan(data)
|
||||
elif is_datetime(data) and isnat(missing_value):
|
||||
return isnat(data)
|
||||
return (data == missing_value)
|
||||
|
||||
|
||||
def busday_count_mask_NaT(begindates, enddates, out=None):
|
||||
@@ -304,8 +326,8 @@ def busday_count_mask_NaT(begindates, enddates, out=None):
|
||||
if out is None:
|
||||
out = empty(broadcast(begindates, enddates).shape, dtype=float)
|
||||
|
||||
beginmask = (begindates == NaTD)
|
||||
endmask = (enddates == NaTD)
|
||||
beginmask = isnat(begindates)
|
||||
endmask = isnat(enddates)
|
||||
|
||||
out = busday_count(
|
||||
# Temporarily fill in non-NaT values.
|
||||
|
||||
Reference in New Issue
Block a user