@@ -215,12 +215,7 @@ def __init__(self, values, freq=None, dtype=None, copy=False):
215
215
216
216
if isinstance (values , type (self )):
217
217
if freq is not None and freq != values .freq :
218
- msg = DIFFERENT_FREQ .format (
219
- cls = type (self ).__name__ ,
220
- own_freq = values .freq .freqstr ,
221
- other_freq = freq .freqstr ,
222
- )
223
- raise IncompatibleFrequency (msg )
218
+ raise raise_on_incompatible (values , freq )
224
219
values , freq = values ._data , values .freq
225
220
226
221
values = np .array (values , dtype = "int64" , copy = copy )
@@ -323,7 +318,7 @@ def _check_compatible_with(self, other):
323
318
if other is NaT :
324
319
return
325
320
if self .freqstr != other .freqstr :
326
- _raise_on_incompatible (self , other )
321
+ raise raise_on_incompatible (self , other )
327
322
328
323
# --------------------------------------------------------------------
329
324
# Data / Attributes
@@ -682,7 +677,7 @@ def _add_offset(self, other):
682
677
assert not isinstance (other , Tick )
683
678
base = libfrequencies .get_base_alias (other .rule_code )
684
679
if base != self .freq .rule_code :
685
- _raise_on_incompatible (self , other )
680
+ raise raise_on_incompatible (self , other )
686
681
687
682
# Note: when calling parent class's _add_timedeltalike_scalar,
688
683
# it will call delta_to_nanoseconds(delta). Because delta here
@@ -750,7 +745,7 @@ def _add_delta(self, other):
750
745
"""
751
746
if not isinstance (self .freq , Tick ):
752
747
# We cannot add timedelta-like to non-tick PeriodArray
753
- _raise_on_incompatible (self , other )
748
+ raise raise_on_incompatible (self , other )
754
749
755
750
new_ordinals = super ()._add_delta (other )
756
751
return type (self )(new_ordinals , freq = self .freq )
@@ -802,28 +797,29 @@ def _check_timedeltalike_freq_compat(self, other):
802
797
# by which will be added to self.
803
798
return delta
804
799
805
- _raise_on_incompatible (self , other )
800
+ raise raise_on_incompatible (self , other )
806
801
807
802
808
803
PeriodArray ._add_comparison_ops ()
809
804
810
805
811
- def _raise_on_incompatible (left , right ):
806
+ def raise_on_incompatible (left , right ):
812
807
"""
813
808
Helper function to render a consistent error message when raising
814
809
IncompatibleFrequency.
815
810
816
811
Parameters
817
812
----------
818
813
left : PeriodArray
819
- right : DateOffset, Period, ndarray, or timedelta-like
814
+ right : None, DateOffset, Period, ndarray, or timedelta-like
820
815
821
- Raises
816
+ Returns
822
817
------
823
818
IncompatibleFrequency
819
+ Exception to be raised by the caller.
824
820
"""
825
821
# GH#24283 error message format depends on whether right is scalar
826
- if isinstance (right , np .ndarray ):
822
+ if isinstance (right , np .ndarray ) or right is None :
827
823
other_freq = None
828
824
elif isinstance (right , (ABCPeriodIndex , PeriodArray , Period , DateOffset )):
829
825
other_freq = right .freqstr
@@ -833,7 +829,7 @@ def _raise_on_incompatible(left, right):
833
829
msg = DIFFERENT_FREQ .format (
834
830
cls = type (left ).__name__ , own_freq = left .freqstr , other_freq = other_freq
835
831
)
836
- raise IncompatibleFrequency (msg )
832
+ return IncompatibleFrequency (msg )
837
833
838
834
839
835
# -------------------------------------------------------------------
0 commit comments