Skip to content

Commit 5fa32e9

Browse files
committed
Handle uint in astype tests
1 parent 3fca810 commit 5fa32e9

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

pandas/tests/arrays/test_datetimes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ def test_astype_to_same(self):
5353
result = arr.astype(DatetimeTZDtype(tz="US/Central"), copy=False)
5454
assert result is arr
5555

56+
@pytest.mark.parametrize("dtype", [
57+
int, np.int32, np.int64, 'uint32', 'uint64',
58+
])
59+
def test_astype_int(self, dtype):
60+
arr = DatetimeArray._from_sequence([pd.Timestamp('2000'),
61+
pd.Timestamp('2001')])
62+
result = arr.astype(dtype)
63+
64+
if np.dtype(dtype).kind == 'u':
65+
expected_dtype = np.dtype('uint64')
66+
else:
67+
expected_dtype = np.dtype('int64')
68+
expected = arr.astype(expected_dtype)
69+
70+
assert result.dtype == expected_dtype
71+
tm.assert_numpy_array_equal(result, expected)
72+
5673
def test_tz_setter_raises(self):
5774
arr = DatetimeArray._from_sequence(['2000'], tz='US/Central')
5875
with pytest.raises(AttributeError, match='tz_localize'):

pandas/tests/arrays/test_period.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,19 @@ def test_take_raises():
8787
arr.take([0, -1], allow_fill=True, fill_value='foo')
8888

8989

90-
@pytest.mark.parametrize('dtype', [int, np.int32, np.int64, 'uint'])
90+
@pytest.mark.parametrize('dtype', [
91+
int, np.int32, np.int64, 'uint32', 'uint64',
92+
])
9193
def test_astype(dtype):
9294
# We choose to ignore the sign and size of integers for
9395
# Period/Datetime/Timedelta astype
9496
arr = period_array(['2000', '2001', None], freq='D')
9597
result = arr.astype(dtype)
96-
expected_dtype = np.dtype('int64')
98+
99+
if np.dtype(dtype).kind == 'u':
100+
expected_dtype = np.dtype('uint64')
101+
else:
102+
expected_dtype = np.dtype('int64')
97103
expected = arr.astype(expected_dtype)
98104

99105
assert result.dtype == expected_dtype

pandas/tests/arrays/test_timedeltas.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,20 @@ def test_neg_freq(self):
5555

5656
result = -arr
5757
tm.assert_timedelta_array_equal(result, expected)
58+
59+
@pytest.mark.parametrize("dtype", [
60+
int, np.int32, np.int64, 'uint32', 'uint64',
61+
])
62+
def test_astype_int(self, dtype):
63+
arr = TimedeltaArray._from_sequence([pd.Timedelta('1H'),
64+
pd.Timedelta('2H')])
65+
result = arr.astype(dtype)
66+
67+
if np.dtype(dtype).kind == 'u':
68+
expected_dtype = np.dtype('uint64')
69+
else:
70+
expected_dtype = np.dtype('int64')
71+
expected = arr.astype(expected_dtype)
72+
73+
assert result.dtype == expected_dtype
74+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)