Python pandas.errors.NullFrequencyError() Examples
The following are 30
code examples of pandas.errors.NullFrequencyError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.errors
, or try the search function
.
Example #1
Source File: test_arithmetic.py From recruit with Apache License 2.0 | 6 votes |
def test_tdi_addsub_integer_array_no_freq(self, box): # GH#19959 tdi = TimedeltaIndex(['1 Day', 'NaT', '3 Hours']) other = box([14, -1, 16]) with pytest.raises(NullFrequencyError): tdi + other with pytest.raises(NullFrequencyError): other + tdi with pytest.raises(NullFrequencyError): tdi - other with pytest.raises(NullFrequencyError): other - tdi # ------------------------------------------------------------- # Binary operations TimedeltaIndex and timedelta-like # Note: add and sub are tested in tests.test_arithmetic, in-place # tests are kept here because their behavior is Index-specific
Example #2
Source File: test_arithmetic.py From coffeegrindsize with MIT License | 6 votes |
def test_tdi_addsub_integer_array_no_freq(self, box): # GH#19959 tdi = TimedeltaIndex(['1 Day', 'NaT', '3 Hours']) other = box([14, -1, 16]) with pytest.raises(NullFrequencyError): tdi + other with pytest.raises(NullFrequencyError): other + tdi with pytest.raises(NullFrequencyError): tdi - other with pytest.raises(NullFrequencyError): other - tdi # ------------------------------------------------------------- # Binary operations TimedeltaIndex and timedelta-like # Note: add and sub are tested in tests.test_arithmetic, in-place # tests are kept here because their behavior is Index-specific
Example #3
Source File: test_timedelta64.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_td64arr_add_sub_numeric_arr_invalid(self, box, vec, dtype): tdser = pd.Series(['59 Days', '59 Days', 'NaT'], dtype='m8[ns]') tdser = tm.box_expected(tdser, box) err = TypeError if box is pd.Index and not dtype.startswith('float'): err = NullFrequencyError vector = vec.astype(dtype) with pytest.raises(err): tdser + vector with pytest.raises(err): vector + tdser with pytest.raises(err): tdser - vector with pytest.raises(err): vector - tdser # ------------------------------------------------------------------ # Operations with timedelta-like others # TODO: this was taken from tests.series.test_ops; de-duplicate
Example #4
Source File: test_timedelta64.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_td64arr_add_sub_numeric_scalar_invalid(self, box_with_array, scalar): box = box_with_array tdser = pd.Series(['59 Days', '59 Days', 'NaT'], dtype='m8[ns]') tdser = tm.box_expected(tdser, box) err = TypeError if box in [pd.Index, tm.to_array] and not isinstance(scalar, float): err = NullFrequencyError with pytest.raises(err): tdser + scalar with pytest.raises(err): scalar + tdser with pytest.raises(err): tdser - scalar with pytest.raises(err): scalar - tdser
Example #5
Source File: test_timeseries.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_shift2(self): ts = Series(np.random.randn(5), index=date_range('1/1/2000', periods=5, freq='H')) result = ts.shift(1, freq='5T') exp_index = ts.index.shift(1, freq='5T') tm.assert_index_equal(result.index, exp_index) # GH #1063, multiple of same base result = ts.shift(1, freq='4H') exp_index = ts.index + offsets.Hour(4) tm.assert_index_equal(result.index, exp_index) idx = DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-04']) msg = "Cannot shift with no freq" with pytest.raises(NullFrequencyError, match=msg): idx.shift(1)
Example #6
Source File: test_arithmetic.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_tdi_addsub_integer_array_no_freq(self, box): # GH#19959 tdi = TimedeltaIndex(['1 Day', 'NaT', '3 Hours']) other = box([14, -1, 16]) with pytest.raises(NullFrequencyError): tdi + other with pytest.raises(NullFrequencyError): other + tdi with pytest.raises(NullFrequencyError): tdi - other with pytest.raises(NullFrequencyError): other - tdi # ------------------------------------------------------------- # Binary operations TimedeltaIndex and timedelta-like # Note: add and sub are tested in tests.test_arithmetic, in-place # tests are kept here because their behavior is Index-specific
Example #7
Source File: test_timedelta64.py From recruit with Apache License 2.0 | 6 votes |
def test_td64arr_add_sub_numeric_arr_invalid(self, box, vec, dtype): tdser = pd.Series(['59 Days', '59 Days', 'NaT'], dtype='m8[ns]') tdser = tm.box_expected(tdser, box) err = TypeError if box is pd.Index and not dtype.startswith('float'): err = NullFrequencyError vector = vec.astype(dtype) with pytest.raises(err): tdser + vector with pytest.raises(err): vector + tdser with pytest.raises(err): tdser - vector with pytest.raises(err): vector - tdser # ------------------------------------------------------------------ # Operations with timedelta-like others # TODO: this was taken from tests.series.test_ops; de-duplicate
Example #8
Source File: test_timedelta64.py From recruit with Apache License 2.0 | 6 votes |
def test_td64arr_add_sub_numeric_scalar_invalid(self, box_with_array, scalar): box = box_with_array tdser = pd.Series(['59 Days', '59 Days', 'NaT'], dtype='m8[ns]') tdser = tm.box_expected(tdser, box) err = TypeError if box in [pd.Index, tm.to_array] and not isinstance(scalar, float): err = NullFrequencyError with pytest.raises(err): tdser + scalar with pytest.raises(err): scalar + tdser with pytest.raises(err): tdser - scalar with pytest.raises(err): scalar - tdser
Example #9
Source File: test_timeseries.py From recruit with Apache License 2.0 | 6 votes |
def test_shift2(self): ts = Series(np.random.randn(5), index=date_range('1/1/2000', periods=5, freq='H')) result = ts.shift(1, freq='5T') exp_index = ts.index.shift(1, freq='5T') tm.assert_index_equal(result.index, exp_index) # GH #1063, multiple of same base result = ts.shift(1, freq='4H') exp_index = ts.index + offsets.Hour(4) tm.assert_index_equal(result.index, exp_index) idx = DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-04']) msg = "Cannot shift with no freq" with pytest.raises(NullFrequencyError, match=msg): idx.shift(1)
Example #10
Source File: test_datetime64.py From recruit with Apache License 2.0 | 5 votes |
def test_dti_add_intarray_no_freq(self, int_holder): # GH#19959 dti = pd.DatetimeIndex(['2016-01-01', 'NaT', '2017-04-05 06:07:08']) other = int_holder([9, 4, -1]) with pytest.raises(NullFrequencyError): dti + other with pytest.raises(NullFrequencyError): other + dti with pytest.raises(NullFrequencyError): dti - other with pytest.raises(TypeError): other - dti # ------------------------------------------------------------- # Binary operations DatetimeIndex and TimedeltaIndex/array
Example #11
Source File: test_timeseries.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_shift2(self): ts = Series(np.random.randn(5), index=date_range('1/1/2000', periods=5, freq='H')) result = ts.shift(1, freq='5T') exp_index = ts.index.shift(1, freq='5T') tm.assert_index_equal(result.index, exp_index) # GH #1063, multiple of same base result = ts.shift(1, freq='4H') exp_index = ts.index + offsets.Hour(4) tm.assert_index_equal(result.index, exp_index) idx = DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-04']) pytest.raises(NullFrequencyError, idx.shift, 1)
Example #12
Source File: test_arithmetic.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_dti_shift_no_freq(self): # GH#19147 dti = pd.DatetimeIndex(['2011-01-01 10:00', '2011-01-01'], freq=None) with pytest.raises(NullFrequencyError): dti.shift(2)
Example #13
Source File: test_arithmetic.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_shift_no_freq(self): # GH#19147 tdi = TimedeltaIndex(['1 days 01:00:00', '2 days 01:00:00'], freq=None) with pytest.raises(NullFrequencyError): tdi.shift(2) # -------------------------------------------------------------
Example #14
Source File: test_arithmetic.py From coffeegrindsize with MIT License | 5 votes |
def test_dti_shift_no_freq(self): # GH#19147 dti = pd.DatetimeIndex(['2011-01-01 10:00', '2011-01-01'], freq=None) with pytest.raises(NullFrequencyError): dti.shift(2)
Example #15
Source File: test_arithmetic.py From recruit with Apache License 2.0 | 5 votes |
def test_shift_no_freq(self): # GH#19147 tdi = TimedeltaIndex(['1 days 01:00:00', '2 days 01:00:00'], freq=None) with pytest.raises(NullFrequencyError): tdi.shift(2) # ------------------------------------------------------------- # Binary operations TimedeltaIndex and integer
Example #16
Source File: test_arithmetic.py From coffeegrindsize with MIT License | 5 votes |
def test_shift_no_freq(self): # GH#19147 tdi = TimedeltaIndex(['1 days 01:00:00', '2 days 01:00:00'], freq=None) with pytest.raises(NullFrequencyError): tdi.shift(2) # ------------------------------------------------------------- # Binary operations TimedeltaIndex and integer
Example #17
Source File: ops.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def dispatch_to_index_op(op, left, right, index_class): """ Wrap Series left in the given index_class to delegate the operation op to the index implementation. DatetimeIndex and TimedeltaIndex perform type checking, timezone handling, overflow checks, etc. Parameters ---------- op : binary operator (operator.add, operator.sub, ...) left : Series right : object index_class : DatetimeIndex or TimedeltaIndex Returns ------- result : object, usually DatetimeIndex, TimedeltaIndex, or Series """ left_idx = index_class(left) # avoid accidentally allowing integer add/sub. For datetime64[tz] dtypes, # left_idx may inherit a freq from a cached DatetimeIndex. # See discussion in GH#19147. if getattr(left_idx, 'freq', None) is not None: left_idx = left_idx._shallow_copy(freq=None) try: result = op(left_idx, right) except NullFrequencyError: # DatetimeIndex and TimedeltaIndex with freq == None raise ValueError # on add/sub of integers (or int-like). We re-raise as a TypeError. raise TypeError('incompatible type for a datetime/timedelta ' 'operation [{name}]'.format(name=op.__name__)) return result
Example #18
Source File: test_datetime64.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_dti_add_intarray_no_freq(self, int_holder): # GH#19959 dti = pd.DatetimeIndex(['2016-01-01', 'NaT', '2017-04-05 06:07:08']) other = int_holder([9, 4, -1]) with pytest.raises(NullFrequencyError): dti + other with pytest.raises(NullFrequencyError): other + dti with pytest.raises(NullFrequencyError): dti - other with pytest.raises(TypeError): other - dti # ------------------------------------------------------------- # Binary operations DatetimeIndex and TimedeltaIndex/array
Example #19
Source File: test_arithmetic.py From recruit with Apache License 2.0 | 5 votes |
def test_dti_shift_no_freq(self): # GH#19147 dti = pd.DatetimeIndex(['2011-01-01 10:00', '2011-01-01'], freq=None) with pytest.raises(NullFrequencyError): dti.shift(2)
Example #20
Source File: test_timedelta64.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_td64arr_add_intlike(self, box_with_array): # GH#19123 tdi = TimedeltaIndex(['59 days', '59 days', 'NaT']) ser = tm.box_expected(tdi, box_with_array) err = TypeError if box_with_array in [pd.Index, tm.to_array]: err = NullFrequencyError other = Series([20, 30, 40], dtype='uint8') # TODO: separate/parametrize with pytest.raises(err): ser + 1 with pytest.raises(err): ser - 1 with pytest.raises(err): ser + other with pytest.raises(err): ser - other with pytest.raises(err): ser + np.array(other) with pytest.raises(err): ser - np.array(other) with pytest.raises(err): ser + pd.Index(other) with pytest.raises(err): ser - pd.Index(other)
Example #21
Source File: test_arithmetic.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_dti_shift_no_freq(self): # GH#19147 dti = pd.DatetimeIndex(['2011-01-01 10:00', '2011-01-01'], freq=None) with pytest.raises(NullFrequencyError): dti.shift(2)
Example #22
Source File: test_timedelta64.py From recruit with Apache License 2.0 | 5 votes |
def test_td64arr_add_intlike(self, box_with_array): # GH#19123 tdi = TimedeltaIndex(['59 days', '59 days', 'NaT']) ser = tm.box_expected(tdi, box_with_array) err = TypeError if box_with_array in [pd.Index, tm.to_array]: err = NullFrequencyError other = Series([20, 30, 40], dtype='uint8') # TODO: separate/parametrize with pytest.raises(err): ser + 1 with pytest.raises(err): ser - 1 with pytest.raises(err): ser + other with pytest.raises(err): ser - other with pytest.raises(err): ser + np.array(other) with pytest.raises(err): ser - np.array(other) with pytest.raises(err): ser + pd.Index(other) with pytest.raises(err): ser - pd.Index(other)
Example #23
Source File: test_arithmetic.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_shift_no_freq(self): # GH#19147 tdi = TimedeltaIndex(['1 days 01:00:00', '2 days 01:00:00'], freq=None) with pytest.raises(NullFrequencyError): tdi.shift(2) # ------------------------------------------------------------- # Binary operations TimedeltaIndex and integer
Example #24
Source File: datetimelike.py From vnpy_crypto with MIT License | 5 votes |
def shift(self, n, freq=None): """ Specialized shift which produces a DatetimeIndex Parameters ---------- n : int Periods to shift by freq : DateOffset or timedelta-like, optional Returns ------- shifted : DatetimeIndex """ if freq is not None and freq != self.freq: if isinstance(freq, compat.string_types): freq = frequencies.to_offset(freq) offset = n * freq result = self + offset if hasattr(self, 'tz'): result._tz = self.tz return result if n == 0: # immutable so OK return self if self.freq is None: raise NullFrequencyError("Cannot shift with no freq") start = self[0] + n * self.freq end = self[-1] + n * self.freq attribs = self._get_attributes_dict() attribs['start'] = start attribs['end'] = end return type(self)(**attribs)
Example #25
Source File: test_timeseries.py From vnpy_crypto with MIT License | 5 votes |
def test_shift2(self): ts = Series(np.random.randn(5), index=date_range('1/1/2000', periods=5, freq='H')) result = ts.shift(1, freq='5T') exp_index = ts.index.shift(1, freq='5T') tm.assert_index_equal(result.index, exp_index) # GH #1063, multiple of same base result = ts.shift(1, freq='4H') exp_index = ts.index + offsets.Hour(4) tm.assert_index_equal(result.index, exp_index) idx = DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-04']) pytest.raises(NullFrequencyError, idx.shift, 1)
Example #26
Source File: test_arithmetic.py From vnpy_crypto with MIT License | 5 votes |
def test_dti_shift_no_freq(self): # GH#19147 dti = pd.DatetimeIndex(['2011-01-01 10:00', '2011-01-01'], freq=None) with pytest.raises(NullFrequencyError): dti.shift(2)
Example #27
Source File: test_arithmetic.py From vnpy_crypto with MIT License | 5 votes |
def test_shift_no_freq(self): # GH#19147 tdi = TimedeltaIndex(['1 days 01:00:00', '2 days 01:00:00'], freq=None) with pytest.raises(NullFrequencyError): tdi.shift(2) # -------------------------------------------------------------
Example #28
Source File: ops.py From recruit with Apache License 2.0 | 5 votes |
def dispatch_to_index_op(op, left, right, index_class): """ Wrap Series left in the given index_class to delegate the operation op to the index implementation. DatetimeIndex and TimedeltaIndex perform type checking, timezone handling, overflow checks, etc. Parameters ---------- op : binary operator (operator.add, operator.sub, ...) left : Series right : object index_class : DatetimeIndex or TimedeltaIndex Returns ------- result : object, usually DatetimeIndex, TimedeltaIndex, or Series """ left_idx = index_class(left) # avoid accidentally allowing integer add/sub. For datetime64[tz] dtypes, # left_idx may inherit a freq from a cached DatetimeIndex. # See discussion in GH#19147. if getattr(left_idx, 'freq', None) is not None: left_idx = left_idx._shallow_copy(freq=None) try: result = op(left_idx, right) except NullFrequencyError: # DatetimeIndex and TimedeltaIndex with freq == None raise ValueError # on add/sub of integers (or int-like). We re-raise as a TypeError. raise TypeError('incompatible type for a datetime/timedelta ' 'operation [{name}]'.format(name=op.__name__)) return result
Example #29
Source File: test_timedelta64.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 4 votes |
def test_addition_ops(self): # with datetimes/timedelta and tdi/dti tdi = TimedeltaIndex(['1 days', pd.NaT, '2 days'], name='foo') dti = pd.date_range('20130101', periods=3, name='bar') td = Timedelta('1 days') dt = Timestamp('20130101') result = tdi + dt expected = DatetimeIndex(['20130102', pd.NaT, '20130103'], name='foo') tm.assert_index_equal(result, expected) result = dt + tdi expected = DatetimeIndex(['20130102', pd.NaT, '20130103'], name='foo') tm.assert_index_equal(result, expected) result = td + tdi expected = TimedeltaIndex(['2 days', pd.NaT, '3 days'], name='foo') tm.assert_index_equal(result, expected) result = tdi + td expected = TimedeltaIndex(['2 days', pd.NaT, '3 days'], name='foo') tm.assert_index_equal(result, expected) # unequal length pytest.raises(ValueError, lambda: tdi + dti[0:1]) pytest.raises(ValueError, lambda: tdi[0:1] + dti) # random indexes with pytest.raises(NullFrequencyError): tdi + pd.Int64Index([1, 2, 3]) # this is a union! # pytest.raises(TypeError, lambda : Int64Index([1,2,3]) + tdi) result = tdi + dti # name will be reset expected = DatetimeIndex(['20130102', pd.NaT, '20130105']) tm.assert_index_equal(result, expected) result = dti + tdi # name will be reset expected = DatetimeIndex(['20130102', pd.NaT, '20130105']) tm.assert_index_equal(result, expected) result = dt + td expected = Timestamp('20130102') assert result == expected result = td + dt expected = Timestamp('20130102') assert result == expected # TODO: Needs more informative name, probably split up into # more targeted tests
Example #30
Source File: test_timedelta64.py From recruit with Apache License 2.0 | 4 votes |
def test_addition_ops(self): # with datetimes/timedelta and tdi/dti tdi = TimedeltaIndex(['1 days', pd.NaT, '2 days'], name='foo') dti = pd.date_range('20130101', periods=3, name='bar') td = Timedelta('1 days') dt = Timestamp('20130101') result = tdi + dt expected = DatetimeIndex(['20130102', pd.NaT, '20130103'], name='foo') tm.assert_index_equal(result, expected) result = dt + tdi expected = DatetimeIndex(['20130102', pd.NaT, '20130103'], name='foo') tm.assert_index_equal(result, expected) result = td + tdi expected = TimedeltaIndex(['2 days', pd.NaT, '3 days'], name='foo') tm.assert_index_equal(result, expected) result = tdi + td expected = TimedeltaIndex(['2 days', pd.NaT, '3 days'], name='foo') tm.assert_index_equal(result, expected) # unequal length pytest.raises(ValueError, lambda: tdi + dti[0:1]) pytest.raises(ValueError, lambda: tdi[0:1] + dti) # random indexes with pytest.raises(NullFrequencyError): tdi + pd.Int64Index([1, 2, 3]) # this is a union! # pytest.raises(TypeError, lambda : Int64Index([1,2,3]) + tdi) result = tdi + dti # name will be reset expected = DatetimeIndex(['20130102', pd.NaT, '20130105']) tm.assert_index_equal(result, expected) result = dti + tdi # name will be reset expected = DatetimeIndex(['20130102', pd.NaT, '20130105']) tm.assert_index_equal(result, expected) result = dt + td expected = Timestamp('20130102') assert result == expected result = td + dt expected = Timestamp('20130102') assert result == expected # TODO: Needs more informative name, probably split up into # more targeted tests