def test_infer_from_tdi_mismatch(self): # GH#23539 # fast-path for invalidating a frequency if the passed data already # has one and it does not match the `freq` input tdi = timedelta_range("1 second", periods=100, freq="1s") msg = ("Inferred frequency .* from passed values does " "not conform to passed frequency") with pytest.raises(ValueError, match=msg): TimedeltaIndex(tdi, freq="D") with pytest.raises(ValueError, match=msg): # GH#23789 TimedeltaArray(tdi, freq="D") with pytest.raises(ValueError, match=msg): TimedeltaIndex(tdi._data, freq="D") with pytest.raises(ValueError, match=msg): TimedeltaArray(tdi._data, freq="D")
def test_explicit_none_freq(self): # Explicitly passing freq=None is respected tdi = timedelta_range(1, periods=5) assert tdi.freq is not None result = TimedeltaIndex(tdi, freq=None) assert result.freq is None result = TimedeltaIndex(tdi._data, freq=None) assert result.freq is None tda = TimedeltaArray(tdi, freq=None) assert tda.freq is None