Python pandas.Timestamp.min() Examples
The following are 30
code examples of pandas.Timestamp.min().
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.Timestamp
, or try the search function
.
Example #1
Source File: test_timestamp.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_basics_nanos(self): val = np.int64(946684800000000000).view('M8[ns]') stamp = Timestamp(val.view('i8') + 500) assert stamp.year == 2000 assert stamp.month == 1 assert stamp.microsecond == 0 assert stamp.nanosecond == 500 # GH 14415 val = np.iinfo(np.int64).min + 80000000000000 stamp = Timestamp(val) assert stamp.year == 1677 assert stamp.month == 9 assert stamp.day == 21 assert stamp.microsecond == 145224 assert stamp.nanosecond == 192
Example #2
Source File: test_timestamp.py From recruit with Apache License 2.0 | 6 votes |
def test_basics_nanos(self): val = np.int64(946684800000000000).view('M8[ns]') stamp = Timestamp(val.view('i8') + 500) assert stamp.year == 2000 assert stamp.month == 1 assert stamp.microsecond == 0 assert stamp.nanosecond == 500 # GH 14415 val = np.iinfo(np.int64).min + 80000000000000 stamp = Timestamp(val) assert stamp.year == 1677 assert stamp.month == 9 assert stamp.day == 21 assert stamp.microsecond == 145224 assert stamp.nanosecond == 192
Example #3
Source File: test_timestamp.py From vnpy_crypto with MIT License | 6 votes |
def test_out_of_bounds_value(self): one_us = np.timedelta64(1).astype('timedelta64[us]') # 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(Timestamp.min).astype('M8[us]') max_ts_us = np.datetime64(Timestamp.max).astype('M8[us]') # No error for the min/max datetimes Timestamp(min_ts_us) Timestamp(max_ts_us) # One us less than the minimum is an error with pytest.raises(ValueError): Timestamp(min_ts_us - one_us) # One us more than the maximum is an error with pytest.raises(ValueError): Timestamp(max_ts_us + one_us)
Example #4
Source File: test_timestamp.py From recruit with Apache License 2.0 | 6 votes |
def test_out_of_bounds_value(self): one_us = np.timedelta64(1).astype('timedelta64[us]') # 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(Timestamp.min).astype('M8[us]') max_ts_us = np.datetime64(Timestamp.max).astype('M8[us]') # No error for the min/max datetimes Timestamp(min_ts_us) Timestamp(max_ts_us) # One us less than the minimum is an error with pytest.raises(ValueError): Timestamp(min_ts_us - one_us) # One us more than the maximum is an error with pytest.raises(ValueError): Timestamp(max_ts_us + one_us)
Example #5
Source File: test_timestamp.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_out_of_bounds_value(self): one_us = np.timedelta64(1).astype('timedelta64[us]') # 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(Timestamp.min).astype('M8[us]') max_ts_us = np.datetime64(Timestamp.max).astype('M8[us]') # No error for the min/max datetimes Timestamp(min_ts_us) Timestamp(max_ts_us) # One us less than the minimum is an error with pytest.raises(ValueError): Timestamp(min_ts_us - one_us) # One us more than the maximum is an error with pytest.raises(ValueError): Timestamp(max_ts_us + one_us)
Example #6
Source File: test_timestamp.py From vnpy_crypto with MIT License | 6 votes |
def test_basics_nanos(self): val = np.int64(946684800000000000).view('M8[ns]') stamp = Timestamp(val.view('i8') + 500) assert stamp.year == 2000 assert stamp.month == 1 assert stamp.microsecond == 0 assert stamp.nanosecond == 500 # GH 14415 val = np.iinfo(np.int64).min + 80000000000000 stamp = Timestamp(val) assert stamp.year == 1677 assert stamp.month == 9 assert stamp.day == 21 assert stamp.microsecond == 145224 assert stamp.nanosecond == 192
Example #7
Source File: stressmodels.py From pastas with MIT License | 6 votes |
def __init__(self, stress, rfunc, name, up=True, cutoff=0.999, settings=None, metadata=None, meanstress=None): if isinstance(stress, list): stress = stress[0] # TODO Temporary fix Raoul, 2017-10-24 stress = TimeSeries(stress, settings=settings, metadata=metadata) if meanstress is None: meanstress = stress.series.std() StressModelBase.__init__(self, rfunc, name, stress.series.index.min(), stress.series.index.max(), up, meanstress, cutoff) self.freq = stress.settings["freq"] self.stress = [stress] self.set_init_parameters()
Example #8
Source File: test_timestamp.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_out_of_bounds_value(self): one_us = np.timedelta64(1).astype('timedelta64[us]') # 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(Timestamp.min).astype('M8[us]') max_ts_us = np.datetime64(Timestamp.max).astype('M8[us]') # No error for the min/max datetimes Timestamp(min_ts_us) Timestamp(max_ts_us) # One us less than the minimum is an error with pytest.raises(ValueError): Timestamp(min_ts_us - one_us) # One us more than the maximum is an error with pytest.raises(ValueError): Timestamp(max_ts_us + one_us)
Example #9
Source File: stressmodels.py From pastas with MIT License | 6 votes |
def __init__(self, prec, evap, oseries=None, dmin=None, dmax=None, rfunc=Exponential, **kwargs): if oseries is not None: if dmin is not None or dmax is not None: msg = 'Please specify either oseries or dmin and dmax' raise (Exception(msg)) o = TimeSeries(oseries).series dmin = o.min() dmax = o.max() elif dmin is None or dmax is None: msg = 'Please specify either oseries or dmin and dmax' raise (Exception(msg)) if not issubclass(rfunc, Exponential): raise NotImplementedError("TarsoModel only supports rfunc " "Exponential!") self.dmin = dmin self.dmax = dmax super().__init__(prec, evap, rfunc=rfunc, **kwargs)
Example #10
Source File: test_timestamp.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_basics_nanos(self): val = np.int64(946684800000000000).view('M8[ns]') stamp = Timestamp(val.view('i8') + 500) assert stamp.year == 2000 assert stamp.month == 1 assert stamp.microsecond == 0 assert stamp.nanosecond == 500 # GH 14415 val = np.iinfo(np.int64).min + 80000000000000 stamp = Timestamp(val) assert stamp.year == 1677 assert stamp.month == 9 assert stamp.day == 21 assert stamp.microsecond == 145224 assert stamp.nanosecond == 192
Example #11
Source File: validation.py From dagster with Apache License 2.0 | 5 votes |
def datetime_column( name, min_datetime=Timestamp.min, max_datetime=Timestamp.max, non_nullable=False, unique=False, ignore_missing_vals=False, is_required=None, ): ''' Simple constructor for PandasColumns that expresses datetime constraints on 'datetime64[ns]' dtypes. Args: name (str): Name of the column. This must match up with the column name in the dataframe you expect to receive. min_datetime (Optional[Union[int,float]]): The lower bound for values you expect in this column. Defaults to pandas.Timestamp.min. max_datetime (Optional[Union[int,float]]): The upper bound for values you expect in this column. Defaults to pandas.Timestamp.max. non_nullable (Optional[bool]): If true, this column will enforce a constraint that all values in the column ought to be non null values. unique (Optional[bool]): If true, this column will enforce a uniqueness constraint on the column values. ignore_missing_vals (Optional[bool]): A flag that is passed into most constraints. If true, the constraint will only evaluate non-null data. Ignore_missing_vals and non_nullable cannot both be True. is_required (Optional[bool]): Flag indicating the optional/required presence of the column. If the column exists the validate function will validate the column. Default to True. ''' return PandasColumn( name=check.str_param(name, 'name'), constraints=[ ColumnDTypeInSetConstraint({'datetime64[ns]'}), InRangeColumnConstraint( min_datetime, max_datetime, ignore_missing_vals=ignore_missing_vals ), ] + _construct_keyword_constraints( non_nullable=non_nullable, unique=unique, ignore_missing_vals=ignore_missing_vals ), is_required=is_required, )
Example #12
Source File: stressmodels.py From pastas with MIT License | 5 votes |
def __init__(self, name="constant", initial=0.0): StressModelBase.__init__(self, One, name, Timestamp.min, Timestamp.max, None, initial, 0) self.set_init_parameters()
Example #13
Source File: stressmodels.py From pastas with MIT License | 5 votes |
def __init__(self, stress, name="factor", settings=None, metadata=None): if isinstance(stress, list): stress = stress[0] # Temporary fix Raoul, 2017-10-24 stress = TimeSeries(stress, settings=settings, metadata=metadata) tmin = stress.series_original.index.min() tmax = stress.series_original.index.max() StressModelBase.__init__(self, One, name, tmin=tmin, tmax=tmax, up=True, meanstress=1, cutoff=0.999) self.value = 1. # Initial value self.stress = [stress] self.set_init_parameters()
Example #14
Source File: utils.py From pastas with MIT License | 5 votes |
def frequency_is_supported(freq): """Method to determine if a frequency is supported for a pastas-model. Parameters ---------- freq: str Returns ------- freq String with the simulation frequency Notes ----- Possible frequency-offsets are listed in: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases The frequency can be a multiple of these offsets, like '7D'. Because of the use in convolution, only frequencies with an equidistant offset are allowed. This means monthly ('M'), yearly ('Y') or even weekly ('W') frequencies are not allowed. Use '7D' for a weekly simulation. D calendar day frequency H hourly frequency T, min minutely frequency S secondly frequency L, ms milliseconds U, us microseconds N nanoseconds TODO: Rename to get_frequency_string and change Returns-documentation """ offset = to_offset(freq) if not hasattr(offset, 'delta'): logger.error("Frequency %s not supported." % freq) else: if offset.n is 1: freq = offset.name else: freq = str(offset.n) + offset.name return freq
Example #15
Source File: model.py From pastas with MIT License | 5 votes |
def _set_time_offset(self): """Internal method to set the time offset for the model class. Notes ----- Method to check if the StressModel timestamps match (e.g. similar hours) """ time_offsets = set() for stressmodel in self.stressmodels.values(): for st in stressmodel.stress: if st.freq_original: # calculate the offset from the default frequency time_offset = get_time_offset( st.series_original.index.min(), self.settings["freq"]) time_offsets.add(time_offset) if len(time_offsets) > 1: msg = ( "The time-differences with the default frequency is not the " "same for all stresses.") self.logger.error(msg) raise (Exception(msg)) if len(time_offsets) == 1: self.settings["time_offset"] = next(iter(time_offsets)) else: self.settings["time_offset"] = Timedelta(0)
Example #16
Source File: stressmodels.py From pastas with MIT License | 5 votes |
def __init__(self, stress, rfunc, name, up=True, cutoff=0.999, settings=("prec", "evap"), metadata=(None, None), meanstress=None): # First check the series, then determine tmin and tmax stress0 = TimeSeries(stress[0], settings=settings[0], metadata=metadata[0]) stress1 = TimeSeries(stress[1], settings=settings[1], metadata=metadata[1]) # Select indices from validated stress where both series are available. index = stress0.series.index.intersection(stress1.series.index) if index.empty: msg = ('The two stresses that were provided have no ' 'overlapping time indices. Please make sure the ' 'indices of the time series overlap.') logger.error(msg) raise Exception(msg) # First check the series, then determine tmin and tmax stress0.update_series(tmin=index.min(), tmax=index.max()) stress1.update_series(tmin=index.min(), tmax=index.max()) if meanstress is None: meanstress = (stress0.series - stress1.series).std() StressModelBase.__init__(self, rfunc, name, index.min(), index.max(), up, meanstress, cutoff) self.stress.append(stress0) self.stress.append(stress1) self.freq = stress0.settings["freq"] self.set_init_parameters()
Example #17
Source File: test_timestamp.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_min_valid(self): # Ensure that Timestamp.min is a valid Timestamp Timestamp(Timestamp.min)
Example #18
Source File: test_timestamp.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_asm8(self): np.random.seed(7960929) ns = [Timestamp.min.value, Timestamp.max.value, 1000] for n in ns: assert (Timestamp(n).asm8.view('i8') == np.datetime64(n, 'ns').view('i8') == n) assert (Timestamp('nat').asm8.view('i8') == np.datetime64('nat', 'ns').view('i8'))
Example #19
Source File: test_timestamp.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_to_datetime_bijective(self): # Ensure that converting to datetime and back only loses precision # by going from nanoseconds to microseconds. exp_warning = None if Timestamp.max.nanosecond == 0 else UserWarning with tm.assert_produces_warning(exp_warning, check_stacklevel=False): assert (Timestamp(Timestamp.max.to_pydatetime()).value / 1000 == Timestamp.max.value / 1000) exp_warning = None if Timestamp.min.nanosecond == 0 else UserWarning with tm.assert_produces_warning(exp_warning, check_stacklevel=False): assert (Timestamp(Timestamp.min.to_pydatetime()).value / 1000 == Timestamp.min.value / 1000)
Example #20
Source File: stressmodels.py From pastas with MIT License | 5 votes |
def __init__(self, start, end, name="linear_trend"): StressModelBase.__init__(self, One, name, Timestamp.min, Timestamp.max, 1, 0, 0) self.start = start self.end = end self.set_init_parameters()
Example #21
Source File: stressmodels.py From pastas with MIT License | 5 votes |
def set_init_parameters(self): self.parameters = self.rfunc.get_init_parameters(self.name) tmin = Timestamp.min.toordinal() tmax = Timestamp.max.toordinal() tinit = self.tstart.toordinal() self.parameters.loc[self.name + "_tstart"] = (tinit, tmin, tmax, False, self.name)
Example #22
Source File: stressmodels.py From pastas with MIT License | 5 votes |
def __init__(self, tstart, name, rfunc=One, up=None): StressModelBase.__init__(self, rfunc, name, Timestamp.min, Timestamp.max, up, 1.0, 0.999) self.tstart = Timestamp(tstart) self.set_init_parameters()
Example #23
Source File: test_timestamp.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_to_datetime_bijective(self): # Ensure that converting to datetime and back only loses precision # by going from nanoseconds to microseconds. exp_warning = None if Timestamp.max.nanosecond == 0 else UserWarning with tm.assert_produces_warning(exp_warning, check_stacklevel=False): assert (Timestamp(Timestamp.max.to_pydatetime()).value / 1000 == Timestamp.max.value / 1000) exp_warning = None if Timestamp.min.nanosecond == 0 else UserWarning with tm.assert_produces_warning(exp_warning, check_stacklevel=False): assert (Timestamp(Timestamp.min.to_pydatetime()).value / 1000 == Timestamp.min.value / 1000)
Example #24
Source File: test_timestamp.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_asm8(self): np.random.seed(7960929) ns = [Timestamp.min.value, Timestamp.max.value, 1000] for n in ns: assert (Timestamp(n).asm8.view('i8') == np.datetime64(n, 'ns').view('i8') == n) assert (Timestamp('nat').asm8.view('i8') == np.datetime64('nat', 'ns').view('i8'))
Example #25
Source File: test_timestamp.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_min_valid(self): # Ensure that Timestamp.min is a valid Timestamp Timestamp(Timestamp.min)
Example #26
Source File: test_timestamp.py From vnpy_crypto with MIT License | 5 votes |
def test_to_datetime_bijective(self): # Ensure that converting to datetime and back only loses precision # by going from nanoseconds to microseconds. exp_warning = None if Timestamp.max.nanosecond == 0 else UserWarning with tm.assert_produces_warning(exp_warning, check_stacklevel=False): assert (Timestamp(Timestamp.max.to_pydatetime()).value / 1000 == Timestamp.max.value / 1000) exp_warning = None if Timestamp.min.nanosecond == 0 else UserWarning with tm.assert_produces_warning(exp_warning, check_stacklevel=False): assert (Timestamp(Timestamp.min.to_pydatetime()).value / 1000 == Timestamp.min.value / 1000)
Example #27
Source File: test_timestamp.py From vnpy_crypto with MIT License | 5 votes |
def test_asm8(self): np.random.seed(7960929) ns = [Timestamp.min.value, Timestamp.max.value, 1000] for n in ns: assert (Timestamp(n).asm8.view('i8') == np.datetime64(n, 'ns').view('i8') == n) assert (Timestamp('nat').asm8.view('i8') == np.datetime64('nat', 'ns').view('i8'))
Example #28
Source File: test_timestamp.py From vnpy_crypto with MIT License | 5 votes |
def test_min_valid(self): # Ensure that Timestamp.min is a valid Timestamp Timestamp(Timestamp.min)
Example #29
Source File: test_timestamp.py From recruit with Apache License 2.0 | 5 votes |
def test_to_datetime_bijective(self): # Ensure that converting to datetime and back only loses precision # by going from nanoseconds to microseconds. exp_warning = None if Timestamp.max.nanosecond == 0 else UserWarning with tm.assert_produces_warning(exp_warning, check_stacklevel=False): assert (Timestamp(Timestamp.max.to_pydatetime()).value / 1000 == Timestamp.max.value / 1000) exp_warning = None if Timestamp.min.nanosecond == 0 else UserWarning with tm.assert_produces_warning(exp_warning, check_stacklevel=False): assert (Timestamp(Timestamp.min.to_pydatetime()).value / 1000 == Timestamp.min.value / 1000)
Example #30
Source File: test_timestamp.py From recruit with Apache License 2.0 | 5 votes |
def test_asm8(self): np.random.seed(7960929) ns = [Timestamp.min.value, Timestamp.max.value, 1000] for n in ns: assert (Timestamp(n).asm8.view('i8') == np.datetime64(n, 'ns').view('i8') == n) assert (Timestamp('nat').asm8.view('i8') == np.datetime64('nat', 'ns').view('i8'))