-
-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
8c62fbb
commit ee2b8b5
Showing
4 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from pandas.core.dtypes.common import is_integer_dtype | ||
|
||
import pandas as pd | ||
import pandas._testing as tm | ||
|
||
arrays = [pd.array([1, 2, 3, None], dtype=dtype) for dtype in tm.ALL_EA_INT_DTYPES] | ||
arrays += [ | ||
pd.array([0.141, -0.268, 5.895, None], dtype=dtype) for dtype in tm.FLOAT_EA_DTYPES | ||
] | ||
|
||
|
||
@pytest.fixture(params=arrays, ids=[a.dtype.name for a in arrays]) | ||
def data(request): | ||
return request.param | ||
|
||
|
||
@pytest.fixture() | ||
def numpy_dtype(data): | ||
# For integer dtype, the numpy conversion must be done to float | ||
if is_integer_dtype(data): | ||
numpy_dtype = float | ||
else: | ||
numpy_dtype = data.dtype.type | ||
return numpy_dtype | ||
|
||
|
||
def test_round(data, numpy_dtype): | ||
# No arguments | ||
result = data.round() | ||
expected = pd.array( | ||
np.round(data.to_numpy(dtype=numpy_dtype, na_value=None)), dtype=data.dtype | ||
) | ||
tm.assert_extension_array_equal(result, expected) | ||
|
||
# Decimals argument | ||
result = data.round(decimals=2) | ||
expected = pd.array( | ||
np.round(data.to_numpy(dtype=numpy_dtype, na_value=None), decimals=2), | ||
dtype=data.dtype, | ||
) | ||
tm.assert_extension_array_equal(result, expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters