def test_freq_setter(self, values, freq, tz): # GH 20678 idx = DatetimeIndex(values, tz=tz) # can set to an offset, converting from string if necessary idx.freq = freq assert idx.freq == freq assert isinstance(idx.freq, ABCDateOffset) # can reset to None idx.freq = None assert idx.freq is None
def test_freq_setter_errors(self): # GH 20678 idx = DatetimeIndex(['20180101', '20180103', '20180105']) # setting with an incompatible freq msg = ('Inferred frequency 2D from passed values does not conform to ' 'passed frequency 5D') with pytest.raises(ValueError, match=msg): idx.freq = '5D' # setting with non-freq string with pytest.raises(ValueError, match='Invalid frequency'): idx.freq = 'foo'
def test_freq_setter_errors(self): # GH 20678 idx = DatetimeIndex(["20180101", "20180103", "20180105"]) # setting with an incompatible freq msg = ("Inferred frequency 2D from passed values does not conform to " "passed frequency 5D") with pytest.raises(ValueError, match=msg): idx.freq = "5D" # setting with non-freq string with pytest.raises(ValueError, match="Invalid frequency"): idx.freq = "foo"
def test_freq_setter_errors(self): # GH 20678 idx = DatetimeIndex(['20180101', '20180103', '20180105']) # setting with an incompatible freq msg = ('Inferred frequency 2D from passed values does not conform to ' 'passed frequency 5D') with tm.assert_raises_regex(ValueError, msg): idx.freq = '5D' # setting with non-freq string with tm.assert_raises_regex(ValueError, 'Invalid frequency'): idx.freq = 'foo'
def parse_input( # pylint: disable=R0201 self, **pars: Dict[str, FloatOrDistVar]) -> Dict[str, FloatOrDistVar]: """Parses parameters before fitting. This should include, e.g., type conversions By default, checks dates and adds frequency. """ dates = pars["dates"] if not isinstance(dates, DatetimeIndex): dates = DatetimeIndex(dates) if not dates.freq: dates.freq = infer_freq(dates) pars["dates"] = dates pars["days_per_step"] = pars["dates"].freq / timedelta(days=1) return pars