Skip to content

Commit

Permalink
Handle uint in astype tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Dec 28, 2018
1 parent 3fca810 commit 5fa32e9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
17 changes: 17 additions & 0 deletions pandas/tests/arrays/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ def test_astype_to_same(self):
result = arr.astype(DatetimeTZDtype(tz="US/Central"), copy=False)
assert result is arr

@pytest.mark.parametrize("dtype", [
int, np.int32, np.int64, 'uint32', 'uint64',
])
def test_astype_int(self, dtype):
arr = DatetimeArray._from_sequence([pd.Timestamp('2000'),
pd.Timestamp('2001')])
result = arr.astype(dtype)

if np.dtype(dtype).kind == 'u':
expected_dtype = np.dtype('uint64')
else:
expected_dtype = np.dtype('int64')
expected = arr.astype(expected_dtype)

assert result.dtype == expected_dtype
tm.assert_numpy_array_equal(result, expected)

def test_tz_setter_raises(self):
arr = DatetimeArray._from_sequence(['2000'], tz='US/Central')
with pytest.raises(AttributeError, match='tz_localize'):
Expand Down
10 changes: 8 additions & 2 deletions pandas/tests/arrays/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,19 @@ def test_take_raises():
arr.take([0, -1], allow_fill=True, fill_value='foo')


@pytest.mark.parametrize('dtype', [int, np.int32, np.int64, 'uint'])
@pytest.mark.parametrize('dtype', [
int, np.int32, np.int64, 'uint32', 'uint64',
])
def test_astype(dtype):
# We choose to ignore the sign and size of integers for
# Period/Datetime/Timedelta astype
arr = period_array(['2000', '2001', None], freq='D')
result = arr.astype(dtype)
expected_dtype = np.dtype('int64')

if np.dtype(dtype).kind == 'u':
expected_dtype = np.dtype('uint64')
else:
expected_dtype = np.dtype('int64')
expected = arr.astype(expected_dtype)

assert result.dtype == expected_dtype
Expand Down
17 changes: 17 additions & 0 deletions pandas/tests/arrays/test_timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,20 @@ def test_neg_freq(self):

result = -arr
tm.assert_timedelta_array_equal(result, expected)

@pytest.mark.parametrize("dtype", [
int, np.int32, np.int64, 'uint32', 'uint64',
])
def test_astype_int(self, dtype):
arr = TimedeltaArray._from_sequence([pd.Timedelta('1H'),
pd.Timedelta('2H')])
result = arr.astype(dtype)

if np.dtype(dtype).kind == 'u':
expected_dtype = np.dtype('uint64')
else:
expected_dtype = np.dtype('int64')
expected = arr.astype(expected_dtype)

assert result.dtype == expected_dtype
tm.assert_numpy_array_equal(result, expected)

0 comments on commit 5fa32e9

Please sign in to comment.