Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions pandas/tests/frame/methods/test_astype.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,38 @@ def test_astype_noncontiguous(self, index_slice):
expected = df.iloc[index_slice]
tm.assert_frame_equal(result, expected, check_dtype=False)

@pytest.mark.parametrize(
"dtype",
tm.ALL_INT_EA_DTYPES + tm.FLOAT_EA_DTYPES,
)
def test_astype_ea_to_datetimetzdtype(self, dtype):
# GH37553
result = Series([4, 0, 9], dtype=dtype).astype(DatetimeTZDtype(tz="US/Pacific"))
expected = Series(
{
0: Timestamp("1969-12-31 16:00:00.000000004-08:00", tz="US/Pacific"),
1: Timestamp("1969-12-31 16:00:00.000000000-08:00", tz="US/Pacific"),
2: Timestamp("1969-12-31 16:00:00.000000009-08:00", tz="US/Pacific"),
}
)

if dtype in tm.FLOAT_EA_DTYPES:
expected = Series(
{
0: Timestamp(
"1970-01-01 00:00:00.000000004-08:00", tz="US/Pacific"
),
1: Timestamp(
"1970-01-01 00:00:00.000000000-08:00", tz="US/Pacific"
),
2: Timestamp(
"1970-01-01 00:00:00.000000009-08:00", tz="US/Pacific"
),
}
)

tm.assert_equal(result, expected)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If just comparing Series, could use tm.assert_series_equal. assert_equal is useful when doing something like parameterizing over DataFrame and Series (like with the frame_or_series fixture)



class TestAstypeCategorical:
def test_astype_from_categorical3(self):
Expand Down