def test_bounds_with_different_units(self): out_of_bounds_dates = ( '1677-09-21', '2262-04-12', ) time_units = ('D', 'h', 'm', 's', 'ms', 'us') for date_string in out_of_bounds_dates: for unit in time_units: self.assertRaises( ValueError, tslib.Timestamp, np.datetime64(date_string, dtype='M8[%s]' % unit) ) in_bounds_dates = ( '1677-09-23', '2262-04-11', ) for date_string in in_bounds_dates: for unit in time_units: tslib.Timestamp( np.datetime64(date_string, dtype='M8[%s]' % unit) )
def test_barely_oob_dts(self): one_us = np.timedelta64(1) # By definition we can't go out of bounds in [ns], so we # convert the datetime64s to [us] so we can go out of bounds min_ts_us = np.datetime64(tslib.Timestamp.min).astype('M8[us]') max_ts_us = np.datetime64(tslib.Timestamp.max).astype('M8[us]') # No error for the min/max datetimes tslib.Timestamp(min_ts_us) tslib.Timestamp(max_ts_us) # One us less than the minimum is an error self.assertRaises(ValueError, tslib.Timestamp, min_ts_us - one_us) # One us more than the maximum is an error self.assertRaises(ValueError, tslib.Timestamp, max_ts_us + one_us)
def _maybe_box_datetimelike(value): # turn a datetime like into a Timestamp/timedelta as needed if isinstance(value, (np.datetime64, datetime)): value = tslib.Timestamp(value) elif isinstance(value, (np.timedelta64, timedelta)): value = tslib.Timedelta(value) return value
def filterDates(dates, minDate='2014-12-24 00:00:01', maxDate='2015-12-05 00:00:01'): minD, maxD = pts.Timestamp(minDate), pts.Timestamp(maxDate) clean = (dates.apply(lambda x: filterDate(x, minD, maxD))) return dates[clean]