Python pandas._libs.tslib.OutOfBoundsDatetime() Examples
The following are 26
code examples of pandas._libs.tslib.OutOfBoundsDatetime().
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._libs.tslib
, or try the search function
.
Example #1
Source File: test_tools.py From recruit with Apache License 2.0 | 6 votes |
def test_datetime_outofbounds_scalar(self, value, format, infer): # GH24763 res = pd.to_datetime(value, errors='ignore', format=format, infer_datetime_format=infer) assert res == value res = pd.to_datetime(value, errors='coerce', format=format, infer_datetime_format=infer) assert res is pd.NaT if format is not None: with pytest.raises(ValueError): pd.to_datetime(value, errors='raise', format=format, infer_datetime_format=infer) else: with pytest.raises(OutOfBoundsDatetime): pd.to_datetime(value, errors='raise', format=format, infer_datetime_format=infer)
Example #2
Source File: test_tools.py From coffeegrindsize with MIT License | 6 votes |
def test_datetime_outofbounds_scalar(self, value, format, infer): # GH24763 res = pd.to_datetime(value, errors='ignore', format=format, infer_datetime_format=infer) assert res == value res = pd.to_datetime(value, errors='coerce', format=format, infer_datetime_format=infer) assert res is pd.NaT if format is not None: with pytest.raises(ValueError): pd.to_datetime(value, errors='raise', format=format, infer_datetime_format=infer) else: with pytest.raises(OutOfBoundsDatetime): pd.to_datetime(value, errors='raise', format=format, infer_datetime_format=infer)
Example #3
Source File: series.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def _set_axis(self, axis, labels, fastpath=False): """ override generic, we want to set the _typ here """ if not fastpath: labels = _ensure_index(labels) is_all_dates = labels.is_all_dates if is_all_dates: if not isinstance(labels, (DatetimeIndex, PeriodIndex, TimedeltaIndex)): try: labels = DatetimeIndex(labels) # need to set here becuase we changed the index if fastpath: self._data.set_axis(axis, labels) except (libts.OutOfBoundsDatetime, ValueError): # labels may exceeds datetime bounds, # or not be a DatetimeIndex pass self._set_subtyp(is_all_dates) object.__setattr__(self, '_index', labels) if not fastpath: self._data.set_axis(axis, labels)
Example #4
Source File: test_tools.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_datetime_outofbounds_scalar(self, value, format, infer): # GH24763 res = pd.to_datetime(value, errors='ignore', format=format, infer_datetime_format=infer) assert res == value res = pd.to_datetime(value, errors='coerce', format=format, infer_datetime_format=infer) assert res is pd.NaT if format is not None: with pytest.raises(ValueError): pd.to_datetime(value, errors='raise', format=format, infer_datetime_format=infer) else: with pytest.raises(OutOfBoundsDatetime): pd.to_datetime(value, errors='raise', format=format, infer_datetime_format=infer)
Example #5
Source File: series.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _set_axis(self, axis, labels, fastpath=False): """ override generic, we want to set the _typ here """ if not fastpath: labels = _ensure_index(labels) is_all_dates = labels.is_all_dates if is_all_dates: if not isinstance(labels, (DatetimeIndex, PeriodIndex, TimedeltaIndex)): try: labels = DatetimeIndex(labels) # need to set here becuase we changed the index if fastpath: self._data.set_axis(axis, labels) except (libts.OutOfBoundsDatetime, ValueError): # labels may exceeds datetime bounds, # or not be a DatetimeIndex pass self._set_subtyp(is_all_dates) object.__setattr__(self, '_index', labels) if not fastpath: self._data.set_axis(axis, labels)
Example #6
Source File: test_array_to_datetime.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_to_datetime_barely_out_of_bounds(self): # GH#19529 # GH#19382 close enough to bounds that dropping nanos would result # in an in-bounds datetime arr = np.array(['2262-04-11 23:47:16.854775808'], dtype=object) with pytest.raises(tslib.OutOfBoundsDatetime): tslib.array_to_datetime(arr)
Example #7
Source File: test_offsets.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_apply_out_of_range(self, tz): if self._offset is None: return # try to create an out-of-bounds result timestamp; if we can't create # the offset skip try: if self._offset in (BusinessHour, CustomBusinessHour): # Using 10000 in BusinessHour fails in tz check because of DST # difference offset = self._get_offset(self._offset, value=100000) else: offset = self._get_offset(self._offset, value=10000) result = Timestamp('20080101') + offset assert isinstance(result, datetime) assert result.tzinfo is None # Check tz is preserved t = Timestamp('20080101', tz=tz) result = t + offset assert isinstance(result, datetime) assert t.tzinfo == result.tzinfo except tslib.OutOfBoundsDatetime: raise except (ValueError, KeyError): # we are creating an invalid offset # so ignore pass
Example #8
Source File: test_tools.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_to_datetime_barely_out_of_bounds(self): # GH#19529 # GH#19382 close enough to bounds that dropping nanos would result # in an in-bounds datetime arr = np.array(['2262-04-11 23:47:16.854775808'], dtype=object) with pytest.raises(OutOfBoundsDatetime): to_datetime(arr)
Example #9
Source File: test_construction.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_construction_outofbounds(self): # GH 13663 dates = [datetime(3000, 1, 1), datetime(4000, 1, 1), datetime(5000, 1, 1), datetime(6000, 1, 1)] exp = Index(dates, dtype=object) # coerces to object tm.assert_index_equal(Index(dates), exp) with pytest.raises(OutOfBoundsDatetime): # can't create DatetimeIndex DatetimeIndex(dates)
Example #10
Source File: test_array_to_datetime.py From coffeegrindsize with MIT License | 5 votes |
def test_to_datetime_barely_out_of_bounds(): # see gh-19382, gh-19529 # # Close enough to bounds that dropping nanos # would result in an in-bounds datetime. arr = np.array(["2262-04-11 23:47:16.854775808"], dtype=object) msg = "Out of bounds nanosecond timestamp: 2262-04-11 23:47:16" with pytest.raises(tslib.OutOfBoundsDatetime, match=msg): tslib.array_to_datetime(arr)
Example #11
Source File: test_tools.py From coffeegrindsize with MIT License | 5 votes |
def test_to_datetime_barely_out_of_bounds(self): # GH#19529 # GH#19382 close enough to bounds that dropping nanos would result # in an in-bounds datetime arr = np.array(['2262-04-11 23:47:16.854775808'], dtype=object) with pytest.raises(OutOfBoundsDatetime): to_datetime(arr)
Example #12
Source File: test_construction.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_construction_outofbounds(self): # GH 13663 dates = [datetime(3000, 1, 1), datetime(4000, 1, 1), datetime(5000, 1, 1), datetime(6000, 1, 1)] exp = Index(dates, dtype=object) # coerces to object tm.assert_index_equal(Index(dates), exp) with pytest.raises(OutOfBoundsDatetime): # can't create DatetimeIndex DatetimeIndex(dates)
Example #13
Source File: test_array_to_datetime.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_to_datetime_barely_out_of_bounds(): # see gh-19382, gh-19529 # # Close enough to bounds that dropping nanos # would result in an in-bounds datetime. arr = np.array(["2262-04-11 23:47:16.854775808"], dtype=object) msg = "Out of bounds nanosecond timestamp: 2262-04-11 23:47:16" with pytest.raises(tslib.OutOfBoundsDatetime, match=msg): tslib.array_to_datetime(arr)
Example #14
Source File: test_tools.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_to_datetime_barely_out_of_bounds(self): # GH#19529 # GH#19382 close enough to bounds that dropping nanos would result # in an in-bounds datetime arr = np.array(['2262-04-11 23:47:16.854775808'], dtype=object) with pytest.raises(OutOfBoundsDatetime): to_datetime(arr)
Example #15
Source File: test_array_to_datetime.py From vnpy_crypto with MIT License | 5 votes |
def test_to_datetime_barely_out_of_bounds(self): # GH#19529 # GH#19382 close enough to bounds that dropping nanos would result # in an in-bounds datetime arr = np.array(['2262-04-11 23:47:16.854775808'], dtype=object) with pytest.raises(tslib.OutOfBoundsDatetime): tslib.array_to_datetime(arr)
Example #16
Source File: test_offsets.py From vnpy_crypto with MIT License | 5 votes |
def test_apply_out_of_range(self, tz): if self._offset is None: return # try to create an out-of-bounds result timestamp; if we can't create # the offset skip try: if self._offset in (BusinessHour, CustomBusinessHour): # Using 10000 in BusinessHour fails in tz check because of DST # difference offset = self._get_offset(self._offset, value=100000) else: offset = self._get_offset(self._offset, value=10000) result = Timestamp('20080101') + offset assert isinstance(result, datetime) assert result.tzinfo is None # Check tz is preserved t = Timestamp('20080101', tz=tz) result = t + offset assert isinstance(result, datetime) assert t.tzinfo == result.tzinfo except tslib.OutOfBoundsDatetime: raise except (ValueError, KeyError): # we are creating an invalid offset # so ignore pass
Example #17
Source File: test_tools.py From vnpy_crypto with MIT License | 5 votes |
def test_to_datetime_barely_out_of_bounds(self): # GH#19529 # GH#19382 close enough to bounds that dropping nanos would result # in an in-bounds datetime arr = np.array(['2262-04-11 23:47:16.854775808'], dtype=object) with pytest.raises(OutOfBoundsDatetime): to_datetime(arr)
Example #18
Source File: test_construction.py From vnpy_crypto with MIT License | 5 votes |
def test_construction_outofbounds(self): # GH 13663 dates = [datetime(3000, 1, 1), datetime(4000, 1, 1), datetime(5000, 1, 1), datetime(6000, 1, 1)] exp = Index(dates, dtype=object) # coerces to object tm.assert_index_equal(Index(dates), exp) with pytest.raises(OutOfBoundsDatetime): # can't create DatetimeIndex DatetimeIndex(dates)
Example #19
Source File: test_array_to_datetime.py From recruit with Apache License 2.0 | 5 votes |
def test_to_datetime_barely_out_of_bounds(): # see gh-19382, gh-19529 # # Close enough to bounds that dropping nanos # would result in an in-bounds datetime. arr = np.array(["2262-04-11 23:47:16.854775808"], dtype=object) msg = "Out of bounds nanosecond timestamp: 2262-04-11 23:47:16" with pytest.raises(tslib.OutOfBoundsDatetime, match=msg): tslib.array_to_datetime(arr)
Example #20
Source File: test_tools.py From recruit with Apache License 2.0 | 5 votes |
def test_to_datetime_barely_out_of_bounds(self): # GH#19529 # GH#19382 close enough to bounds that dropping nanos would result # in an in-bounds datetime arr = np.array(['2262-04-11 23:47:16.854775808'], dtype=object) with pytest.raises(OutOfBoundsDatetime): to_datetime(arr)
Example #21
Source File: test_tools.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 4 votes |
def test_unit(self, cache): # GH 11758 # test proper behavior with erros with pytest.raises(ValueError): to_datetime([1], unit='D', format='%Y%m%d', cache=cache) values = [11111111, 1, 1.0, iNaT, NaT, np.nan, 'NaT', ''] result = to_datetime(values, unit='D', errors='ignore', cache=cache) expected = Index([11111111, Timestamp('1970-01-02'), Timestamp('1970-01-02'), NaT, NaT, NaT, NaT, NaT], dtype=object) tm.assert_index_equal(result, expected) result = to_datetime(values, unit='D', errors='coerce', cache=cache) expected = DatetimeIndex(['NaT', '1970-01-02', '1970-01-02', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT']) tm.assert_index_equal(result, expected) with pytest.raises(tslib.OutOfBoundsDatetime): to_datetime(values, unit='D', errors='raise', cache=cache) values = [1420043460000, iNaT, NaT, np.nan, 'NaT'] result = to_datetime(values, errors='ignore', unit='s', cache=cache) expected = Index([1420043460000, NaT, NaT, NaT, NaT], dtype=object) tm.assert_index_equal(result, expected) result = to_datetime(values, errors='coerce', unit='s', cache=cache) expected = DatetimeIndex(['NaT', 'NaT', 'NaT', 'NaT', 'NaT']) tm.assert_index_equal(result, expected) with pytest.raises(tslib.OutOfBoundsDatetime): to_datetime(values, errors='raise', unit='s', cache=cache) # if we have a string, then we raise a ValueError # and NOT an OutOfBoundsDatetime for val in ['foo', Timestamp('20130101')]: try: to_datetime(val, errors='raise', unit='s', cache=cache) except tslib.OutOfBoundsDatetime: raise AssertionError("incorrect exception raised") except ValueError: pass
Example #22
Source File: test_tools.py From elasticintel with GNU General Public License v3.0 | 4 votes |
def test_unit(self): # GH 11758 # test proper behavior with erros with pytest.raises(ValueError): to_datetime([1], unit='D', format='%Y%m%d') values = [11111111, 1, 1.0, tslib.iNaT, NaT, np.nan, 'NaT', ''] result = to_datetime(values, unit='D', errors='ignore') expected = Index([11111111, Timestamp('1970-01-02'), Timestamp('1970-01-02'), NaT, NaT, NaT, NaT, NaT], dtype=object) tm.assert_index_equal(result, expected) result = to_datetime(values, unit='D', errors='coerce') expected = DatetimeIndex(['NaT', '1970-01-02', '1970-01-02', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT']) tm.assert_index_equal(result, expected) with pytest.raises(tslib.OutOfBoundsDatetime): to_datetime(values, unit='D', errors='raise') values = [1420043460000, tslib.iNaT, NaT, np.nan, 'NaT'] result = to_datetime(values, errors='ignore', unit='s') expected = Index([1420043460000, NaT, NaT, NaT, NaT], dtype=object) tm.assert_index_equal(result, expected) result = to_datetime(values, errors='coerce', unit='s') expected = DatetimeIndex(['NaT', 'NaT', 'NaT', 'NaT', 'NaT']) tm.assert_index_equal(result, expected) with pytest.raises(tslib.OutOfBoundsDatetime): to_datetime(values, errors='raise', unit='s') # if we have a string, then we raise a ValueError # and NOT an OutOfBoundsDatetime for val in ['foo', Timestamp('20130101')]: try: to_datetime(val, errors='raise', unit='s') except tslib.OutOfBoundsDatetime: raise AssertionError("incorrect exception raised") except ValueError: pass
Example #23
Source File: test_tools.py From coffeegrindsize with MIT License | 4 votes |
def test_unit(self, cache): # GH 11758 # test proper behavior with erros with pytest.raises(ValueError): to_datetime([1], unit='D', format='%Y%m%d', cache=cache) values = [11111111, 1, 1.0, iNaT, NaT, np.nan, 'NaT', ''] result = to_datetime(values, unit='D', errors='ignore', cache=cache) expected = Index([11111111, Timestamp('1970-01-02'), Timestamp('1970-01-02'), NaT, NaT, NaT, NaT, NaT], dtype=object) tm.assert_index_equal(result, expected) result = to_datetime(values, unit='D', errors='coerce', cache=cache) expected = DatetimeIndex(['NaT', '1970-01-02', '1970-01-02', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT']) tm.assert_index_equal(result, expected) with pytest.raises(tslib.OutOfBoundsDatetime): to_datetime(values, unit='D', errors='raise', cache=cache) values = [1420043460000, iNaT, NaT, np.nan, 'NaT'] result = to_datetime(values, errors='ignore', unit='s', cache=cache) expected = Index([1420043460000, NaT, NaT, NaT, NaT], dtype=object) tm.assert_index_equal(result, expected) result = to_datetime(values, errors='coerce', unit='s', cache=cache) expected = DatetimeIndex(['NaT', 'NaT', 'NaT', 'NaT', 'NaT']) tm.assert_index_equal(result, expected) with pytest.raises(tslib.OutOfBoundsDatetime): to_datetime(values, errors='raise', unit='s', cache=cache) # if we have a string, then we raise a ValueError # and NOT an OutOfBoundsDatetime for val in ['foo', Timestamp('20130101')]: try: to_datetime(val, errors='raise', unit='s', cache=cache) except tslib.OutOfBoundsDatetime: raise AssertionError("incorrect exception raised") except ValueError: pass
Example #24
Source File: test_tools.py From vnpy_crypto with MIT License | 4 votes |
def test_unit(self, cache): # GH 11758 # test proper behavior with erros with pytest.raises(ValueError): to_datetime([1], unit='D', format='%Y%m%d', cache=cache) values = [11111111, 1, 1.0, tslib.iNaT, NaT, np.nan, 'NaT', ''] result = to_datetime(values, unit='D', errors='ignore', cache=cache) expected = Index([11111111, Timestamp('1970-01-02'), Timestamp('1970-01-02'), NaT, NaT, NaT, NaT, NaT], dtype=object) tm.assert_index_equal(result, expected) result = to_datetime(values, unit='D', errors='coerce', cache=cache) expected = DatetimeIndex(['NaT', '1970-01-02', '1970-01-02', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT']) tm.assert_index_equal(result, expected) with pytest.raises(tslib.OutOfBoundsDatetime): to_datetime(values, unit='D', errors='raise', cache=cache) values = [1420043460000, tslib.iNaT, NaT, np.nan, 'NaT'] result = to_datetime(values, errors='ignore', unit='s', cache=cache) expected = Index([1420043460000, NaT, NaT, NaT, NaT], dtype=object) tm.assert_index_equal(result, expected) result = to_datetime(values, errors='coerce', unit='s', cache=cache) expected = DatetimeIndex(['NaT', 'NaT', 'NaT', 'NaT', 'NaT']) tm.assert_index_equal(result, expected) with pytest.raises(tslib.OutOfBoundsDatetime): to_datetime(values, errors='raise', unit='s', cache=cache) # if we have a string, then we raise a ValueError # and NOT an OutOfBoundsDatetime for val in ['foo', Timestamp('20130101')]: try: to_datetime(val, errors='raise', unit='s', cache=cache) except tslib.OutOfBoundsDatetime: raise AssertionError("incorrect exception raised") except ValueError: pass
Example #25
Source File: test_tools.py From twitter-stock-recommendation with MIT License | 4 votes |
def test_unit(self, cache): # GH 11758 # test proper behavior with erros with pytest.raises(ValueError): to_datetime([1], unit='D', format='%Y%m%d', cache=cache) values = [11111111, 1, 1.0, tslib.iNaT, NaT, np.nan, 'NaT', ''] result = to_datetime(values, unit='D', errors='ignore', cache=cache) expected = Index([11111111, Timestamp('1970-01-02'), Timestamp('1970-01-02'), NaT, NaT, NaT, NaT, NaT], dtype=object) tm.assert_index_equal(result, expected) result = to_datetime(values, unit='D', errors='coerce', cache=cache) expected = DatetimeIndex(['NaT', '1970-01-02', '1970-01-02', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT']) tm.assert_index_equal(result, expected) with pytest.raises(tslib.OutOfBoundsDatetime): to_datetime(values, unit='D', errors='raise', cache=cache) values = [1420043460000, tslib.iNaT, NaT, np.nan, 'NaT'] result = to_datetime(values, errors='ignore', unit='s', cache=cache) expected = Index([1420043460000, NaT, NaT, NaT, NaT], dtype=object) tm.assert_index_equal(result, expected) result = to_datetime(values, errors='coerce', unit='s', cache=cache) expected = DatetimeIndex(['NaT', 'NaT', 'NaT', 'NaT', 'NaT']) tm.assert_index_equal(result, expected) with pytest.raises(tslib.OutOfBoundsDatetime): to_datetime(values, errors='raise', unit='s', cache=cache) # if we have a string, then we raise a ValueError # and NOT an OutOfBoundsDatetime for val in ['foo', Timestamp('20130101')]: try: to_datetime(val, errors='raise', unit='s', cache=cache) except tslib.OutOfBoundsDatetime: raise AssertionError("incorrect exception raised") except ValueError: pass
Example #26
Source File: test_tools.py From recruit with Apache License 2.0 | 4 votes |
def test_unit(self, cache): # GH 11758 # test proper behavior with erros with pytest.raises(ValueError): to_datetime([1], unit='D', format='%Y%m%d', cache=cache) values = [11111111, 1, 1.0, iNaT, NaT, np.nan, 'NaT', ''] result = to_datetime(values, unit='D', errors='ignore', cache=cache) expected = Index([11111111, Timestamp('1970-01-02'), Timestamp('1970-01-02'), NaT, NaT, NaT, NaT, NaT], dtype=object) tm.assert_index_equal(result, expected) result = to_datetime(values, unit='D', errors='coerce', cache=cache) expected = DatetimeIndex(['NaT', '1970-01-02', '1970-01-02', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT']) tm.assert_index_equal(result, expected) with pytest.raises(tslib.OutOfBoundsDatetime): to_datetime(values, unit='D', errors='raise', cache=cache) values = [1420043460000, iNaT, NaT, np.nan, 'NaT'] result = to_datetime(values, errors='ignore', unit='s', cache=cache) expected = Index([1420043460000, NaT, NaT, NaT, NaT], dtype=object) tm.assert_index_equal(result, expected) result = to_datetime(values, errors='coerce', unit='s', cache=cache) expected = DatetimeIndex(['NaT', 'NaT', 'NaT', 'NaT', 'NaT']) tm.assert_index_equal(result, expected) with pytest.raises(tslib.OutOfBoundsDatetime): to_datetime(values, errors='raise', unit='s', cache=cache) # if we have a string, then we raise a ValueError # and NOT an OutOfBoundsDatetime for val in ['foo', Timestamp('20130101')]: try: to_datetime(val, errors='raise', unit='s', cache=cache) except tslib.OutOfBoundsDatetime: raise AssertionError("incorrect exception raised") except ValueError: pass