Esempio n. 1
0
 def test_replace_invalid_kwarg(self, tz_aware_fixture):
     tz = tz_aware_fixture
     # GH#14621, GH#7825
     ts = Timestamp("2016-01-01 09:00:00.000000123", tz=tz)
     msg = r"replace\(\) got an unexpected keyword argument"
     with pytest.raises(TypeError, match=msg):
         ts.replace(foo=5)
Esempio n. 2
0
 def test_replace_integer_args(self, tz_aware_fixture):
     tz = tz_aware_fixture
     # GH#14621, GH#7825
     ts = Timestamp("2016-01-01 09:00:00.000000123", tz=tz)
     msg = "value must be an integer, received <class 'float'> for hour"
     with pytest.raises(ValueError, match=msg):
         ts.replace(hour=0.1)
Esempio n. 3
0
 def test_replace_preserves_nanos(self, tz_aware_fixture):
     tz = tz_aware_fixture
     # GH#14621, GH#7825
     ts = Timestamp("2016-01-01 09:00:00.000000123", tz=tz)
     result = ts.replace(hour=0)
     expected = Timestamp("2016-01-01 00:00:00.000000123", tz=tz)
     assert result == expected
Esempio n. 4
0
 def test_replace_dst_border(self, unit):
     # Gh 7825
     t = Timestamp("2013-11-3", tz="America/Chicago")._as_unit(unit)
     result = t.replace(hour=3)
     expected = Timestamp("2013-11-3 03:00:00", tz="America/Chicago")
     assert result == expected
     assert result._reso == getattr(NpyDatetimeUnit, f"NPY_FR_{unit}").value
Esempio n. 5
0
 def test_replace_dst_fold(self, fold, tz):
     # GH 25017
     d = datetime(2019, 10, 27, 2, 30)
     ts = Timestamp(d, tz=tz)
     result = ts.replace(hour=1, fold=fold)
     expected = Timestamp(datetime(2019, 10, 27, 1,
                                   30)).tz_localize(tz, ambiguous=not fold)
     assert result == expected
Esempio n. 6
0
 def test_replace_aware(self, tz_aware_fixture):
     tz = tz_aware_fixture
     # GH#14621, GH#7825
     # replacing datetime components with and w/o presence of a timezone
     ts = Timestamp("2016-01-01 09:00:00", tz=tz)
     result = ts.replace(hour=0)
     expected = Timestamp("2016-01-01 00:00:00", tz=tz)
     assert result == expected
Esempio n. 7
0
def test_replace_preserves_fold(fold):
    # GH 37610. Check that replace preserves Timestamp fold property
    tz = gettz("Europe/Moscow")

    ts = Timestamp(year=2009, month=10, day=25, hour=2, minute=30, fold=fold, tzinfo=tz)
    ts_replaced = ts.replace(second=1)

    assert ts_replaced.fold == fold
Esempio n. 8
0
 def test_replace_dst_fold(self, fold, tz, unit):
     # GH 25017
     d = datetime(2019, 10, 27, 2, 30)
     ts = Timestamp(d, tz=tz)._as_unit(unit)
     result = ts.replace(hour=1, fold=fold)
     expected = Timestamp(datetime(2019, 10, 27, 1,
                                   30)).tz_localize(tz, ambiguous=not fold)
     assert result == expected
     assert result._reso == getattr(NpyDatetimeUnit, f"NPY_FR_{unit}").value
Esempio n. 9
0
 def test_replace_multiple(self, tz_aware_fixture):
     tz = tz_aware_fixture
     # GH#14621, GH#7825
     # replacing datetime components with and w/o presence of a timezone
     # test all
     ts = Timestamp("2016-01-01 09:00:00.000000123", tz=tz)
     result = ts.replace(
         year=2015,
         month=2,
         day=2,
         hour=0,
         minute=5,
         second=5,
         microsecond=5,
         nanosecond=5,
     )
     expected = Timestamp("2015-02-02 00:05:05.000005005", tz=tz)
     assert result == expected
Esempio n. 10
0
 def test_replace_dst_border(self):
     # Gh 7825
     t = Timestamp("2013-11-3", tz="America/Chicago")
     result = t.replace(hour=3)
     expected = Timestamp("2013-11-3 03:00:00", tz="America/Chicago")
     assert result == expected
Esempio n. 11
0
 def test_replace_tzinfo_equiv_tz_localize_none(self):
     # GH#14621, GH#7825
     # assert conversion to naive is the same as replacing tzinfo with None
     ts = Timestamp("2013-11-03 01:59:59.999999-0400", tz="US/Eastern")
     assert ts.tz_localize(None) == ts.replace(tzinfo=None)
Esempio n. 12
0
 def test_replace_naive(self):
     # GH#14621, GH#7825
     ts = Timestamp("2016-01-01 09:00:00")
     result = ts.replace(hour=0)
     expected = Timestamp("2016-01-01 00:00:00")
     assert result == expected