diff --git a/pandas/tests/indexes/datetimes/test_constructors.py b/pandas/tests/indexes/datetimes/test_constructors.py index 434605e5011ca8..599ae9a028fdcc 100644 --- a/pandas/tests/indexes/datetimes/test_constructors.py +++ b/pandas/tests/indexes/datetimes/test_constructors.py @@ -965,7 +965,7 @@ def test_dti_tz_constructors(self, tzstr): start="2005-11-10 08:00:00", freq="h", periods=2, tz=tzstr, unit="s" ) idx2 = idx2._with_freq(None) # the others all have freq=None - idx3 = DatetimeIndex(arr, tz=tzstr).as_unit("s") # .as_unit("ns") + idx3 = DatetimeIndex(arr, tz=tzstr).as_unit("s") idx4 = DatetimeIndex(np.array(arr), tz=tzstr).as_unit("s") tm.assert_index_equal(idx1, idx2) diff --git a/pandas/tests/reshape/concat/test_datetimes.py b/pandas/tests/reshape/concat/test_datetimes.py index bb4b3ee93c4d47..f126e05e06eb95 100644 --- a/pandas/tests/reshape/concat/test_datetimes.py +++ b/pandas/tests/reshape/concat/test_datetimes.py @@ -61,8 +61,6 @@ def test_concat_datetime_timezone(self): ], freq="h", ) - .as_unit("ns") - .tz_convert("UTC") .tz_convert("Europe/Paris") .as_unit("ns") ) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 06a580a6052de1..385320dcb5d04a 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -975,7 +975,7 @@ def test_constructor_dtype_datetime64_10(self): # GH3414 related expected = Series(pydates, dtype="datetime64[ms]") - result = Series(Series(dates).view(np.int64) / 1000, dtype="M8[ms]") + result = Series(Series(dates).astype(np.int64) / 1000, dtype="M8[ms]") tm.assert_series_equal(result, expected) result = Series(dates, dtype="datetime64[ms]") diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 301b589e1ce3ad..89f6780dd2597f 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -255,7 +255,6 @@ def test_to_datetime_format_YYYYMMDD_with_none(self, input_s): def test_to_datetime_format_YYYYMMDD_overflow(self, input_s, expected): # GH 25512 # format='%Y%m%d', errors='coerce' - # expected = expected.dt.as_unit("ns") result = to_datetime(input_s, format="%Y%m%d", errors="coerce") tm.assert_series_equal(result, expected) @@ -277,7 +276,6 @@ def test_to_datetime_format_YYYYMMDD_overflow(self, input_s, expected): ) def test_to_datetime_with_NA(self, data, format, expected): # GH#42957 - # expected = expected.as_unit("ns") result = to_datetime(data, format=format) tm.assert_index_equal(result, expected) @@ -494,7 +492,7 @@ def test_to_datetime_format_weeks(self, value, fmt, expected, cache): def test_to_datetime_parse_tzname_or_tzoffset(self, fmt, dates, expected_dates): # GH 13486 result = to_datetime(dates, format=fmt) - expected = Index(expected_dates) # .as_unit("ns") + expected = Index(expected_dates) tm.assert_equal(result, expected) @pytest.mark.parametrize( @@ -554,7 +552,7 @@ def test_to_datetime_parse_tzname_or_tzoffset_different_tz_to_utc(self): fmt = "%Y-%m-%d %H:%M:%S %z" result = to_datetime(dates, format=fmt, utc=True) - expected = DatetimeIndex(expected_dates) # .as_unit("ns") + expected = DatetimeIndex(expected_dates) tm.assert_index_equal(result, expected) @pytest.mark.parametrize( @@ -580,9 +578,7 @@ def test_to_datetime_parse_timezone_keeps_name(self): fmt = "%Y-%m-%d %H:%M:%S %z" arg = Index(["2010-01-01 12:00:00 Z"], name="foo") result = to_datetime(arg, format=fmt) - expected = DatetimeIndex( - ["2010-01-01 12:00:00"], tz="UTC", name="foo" - ) # .as_unit("ns") + expected = DatetimeIndex(["2010-01-01 12:00:00"], tz="UTC", name="foo") tm.assert_index_equal(result, expected) @@ -615,9 +611,7 @@ def test_to_datetime_mixed_datetime_and_string(self): d1 = datetime(2020, 1, 1, 17, tzinfo=timezone(-timedelta(hours=1))) d2 = datetime(2020, 1, 1, 18, tzinfo=timezone(-timedelta(hours=1))) res = to_datetime(["2020-01-01 17:00 -0100", d2]) - expected = to_datetime([d1, d2]).tz_convert( - timezone(timedelta(minutes=-60)) - ) # .as_unit("ns") + expected = to_datetime([d1, d2]).tz_convert(timezone(timedelta(minutes=-60))) tm.assert_index_equal(res, expected) def test_to_datetime_mixed_string_and_numeric(self): @@ -641,7 +635,7 @@ def test_to_datetime_mixed_date_and_string(self, format): # https://github.com/pandas-dev/pandas/issues/50108 d1 = date(2020, 1, 2) res = to_datetime(["2020-01-01", d1], format=format) - expected = DatetimeIndex(["2020-01-01", "2020-01-02"]) # .as_unit("ns") + expected = DatetimeIndex(["2020-01-01", "2020-01-02"]) tm.assert_index_equal(res, expected) @pytest.mark.parametrize( @@ -1140,7 +1134,7 @@ def test_to_datetime_dt64s(self, cache, dt): def test_to_datetime_dt64s_and_str(self, arg, format): # https://github.com/pandas-dev/pandas/issues/50036 result = to_datetime([arg, np.datetime64("2020-01-01")], format=format) - expected = DatetimeIndex(["2001-01-01", "2020-01-01"]) # .as_unit("ns") + expected = DatetimeIndex(["2001-01-01", "2020-01-01"]) tm.assert_index_equal(result, expected) @pytest.mark.parametrize( @@ -1734,11 +1728,11 @@ def test_iso_8601_strings_with_same_offset(self): expected = Timestamp(ts_str) assert result == expected - expected = DatetimeIndex([Timestamp(ts_str)] * 2) # .as_unit("ns") + expected = DatetimeIndex([Timestamp(ts_str)] * 2) result = to_datetime([ts_str] * 2) tm.assert_index_equal(result, expected) - result = DatetimeIndex([ts_str] * 2) # .as_unit("ns") + result = DatetimeIndex([ts_str] * 2) tm.assert_index_equal(result, expected) def test_iso_8601_strings_with_different_offsets(self): @@ -3696,9 +3690,7 @@ def test_to_datetime_format_f_parse_nanos(): def test_to_datetime_mixed_iso8601(): # https://github.com/pandas-dev/pandas/issues/50411 result = to_datetime(["2020-01-01", "2020-01-01 05:00:00"], format="ISO8601") - expected = DatetimeIndex( - ["2020-01-01 00:00:00", "2020-01-01 05:00:00"] - ) # .as_unit("ns") + expected = DatetimeIndex(["2020-01-01 00:00:00", "2020-01-01 05:00:00"]) tm.assert_index_equal(result, expected) @@ -3767,13 +3759,12 @@ def test_to_datetime_with_empty_str_utc_false_format_mixed(): # GH 50887 vals = ["2020-01-01 00:00+00:00", ""] result = to_datetime(vals, format="mixed") - expected = Index([Timestamp("2020-01-01 00:00+00:00"), "NaT"], dtype="M8[ns, UTC]") + expected = Index([Timestamp("2020-01-01 00:00+00:00"), "NaT"], dtype="M8[s, UTC]") tm.assert_index_equal(result, expected) # Check that a couple of other similar paths work the same way - # FIXME: expect the same reso! alt = to_datetime(vals) - tm.assert_index_equal(alt, expected.as_unit("s")) + tm.assert_index_equal(alt, expected) alt2 = DatetimeIndex(vals) tm.assert_index_equal(alt2, expected)