@@ -19,7 +19,7 @@ cnp.import_array()
19
19
20
20
21
21
from pandas._libs.tslibs cimport util
22
- from pandas._libs.tslibs.util cimport is_integer_object
22
+ from pandas._libs.tslibs.util cimport is_integer_object, is_datetime64_object
23
23
24
24
from pandas._libs.tslibs.base cimport ABCTimestamp
25
25
@@ -170,7 +170,7 @@ def apply_wraps(func):
170
170
elif isinstance (other, (timedelta, BaseOffset)):
171
171
# timedelta path
172
172
return func(self , other)
173
- elif isinstance (other, (np.datetime64, datetime, date)):
173
+ elif isinstance (other, (datetime, date)) or is_datetime64_object(other ):
174
174
other = as_timestamp(other)
175
175
else :
176
176
# This will end up returning NotImplemented back in __add__
@@ -661,6 +661,8 @@ cdef class _BaseOffset:
661
661
662
662
# ------------------------------------------------------------------
663
663
664
+ # Staticmethod so we can call from _Tick.__init__, will be unnecessary
665
+ # once BaseOffset is a cdef class and is inherited by _Tick
664
666
@staticmethod
665
667
def _validate_n (n ):
666
668
"""
@@ -781,25 +783,63 @@ cdef class _Tick(_BaseOffset):
781
783
# ensure that reversed-ops with numpy scalars return NotImplemented
782
784
__array_priority__ = 1000
783
785
_adjust_dst = False
786
+ _prefix = " undefined"
787
+ _attributes = frozenset ([" n" , " normalize" ])
784
788
785
789
def __init__ (self , n = 1 , normalize = False ):
786
- n = _BaseOffset ._validate_n(n)
790
+ n = self ._validate_n(n)
787
791
self .n = n
788
- self .normalize = normalize
792
+ self .normalize = False
789
793
self ._cache = {}
790
-
791
794
if normalize:
792
795
# GH#21427
793
796
raise ValueError (
794
797
" Tick offset with `normalize=True` are not allowed."
795
798
)
796
799
800
+ @property
801
+ def delta (self ):
802
+ return self .n * self ._inc
803
+
804
+ @property
805
+ def nanos (self ) -> int64_t:
806
+ return self.delta.value
807
+
797
808
def is_on_offset(self , dt ) -> bool:
798
809
return True
799
810
800
811
def is_anchored(self ) -> bool:
801
812
return False
802
813
814
+ # --------------------------------------------------------------------
815
+ # Comparison and Arithmetic Methods
816
+
817
+ def __eq__(self , other ):
818
+ if isinstance (other, str ):
819
+ try :
820
+ # GH#23524 if to_offset fails, we are dealing with an
821
+ # incomparable type so == is False and != is True
822
+ other = to_offset(other)
823
+ except ValueError :
824
+ # e.g. "infer"
825
+ return False
826
+ return self .delta == other
827
+
828
+ def __ne__ (self , other ):
829
+ return not (self == other)
830
+
831
+ def __le__ (self , other ):
832
+ return self .delta.__le__ (other)
833
+
834
+ def __lt__ (self , other ):
835
+ return self .delta.__lt__ (other)
836
+
837
+ def __ge__ (self , other ):
838
+ return self .delta.__ge__ (other)
839
+
840
+ def __gt__ (self , other ):
841
+ return self .delta.__gt__ (other)
842
+
803
843
def __truediv__ (self , other ):
804
844
if not isinstance (self , _Tick):
805
845
# cython semantics mean the args are sometimes swapped
@@ -808,6 +848,9 @@ cdef class _Tick(_BaseOffset):
808
848
result = self .delta.__truediv__ (other)
809
849
return _wrap_timedelta_result(result)
810
850
851
+ # --------------------------------------------------------------------
852
+ # Pickle Methods
853
+
811
854
def __reduce__ (self ):
812
855
return (type (self ), (self .n,))
813
856
0 commit comments