Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel committed Nov 27, 2023
1 parent 12e57cf commit 9005743
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/reshape/concat/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
Expand Down
31 changes: 11 additions & 20 deletions pandas/tests/tools/test_to_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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)


Expand Down Expand Up @@ -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):
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 9005743

Please sign in to comment.