Skip to content

Commit

Permalink
MAINT: Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyoung committed Jan 30, 2019
1 parent ef29aab commit 1579b3f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
10 changes: 5 additions & 5 deletions pandas/core/tools/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def to_numeric(arg, errors='raise', downcast=None):
Please note that precision loss may occur if really large numbers
are passed in. Due to the internal limitations of `ndarray`, if
numbers smaller than `-9223372036854775808` or larger than
`18446744073709551615` are passed in, it is very likely they
will be converted to float so that they can stored in an `ndarray`.
These warnings apply similarly to `Series` since it internally
leverages `ndarray`.
numbers smaller than `-9223372036854775808` (np.iinfo(np.int64).min)
or larger than `18446744073709551615` (np.iinfo(np.uint64).max) are
passed in, it is very likely they will be converted to float so that
they can stored in an `ndarray`. These warnings apply similarly to
`Series` since it internally leverages `ndarray`.
Parameters
----------
Expand Down
74 changes: 37 additions & 37 deletions pandas/tests/tools/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,43 @@
from pandas.util import testing as tm


@pytest.fixture(params=[None, "ignore", "raise", "coerce"])
def errors(request):
return request.param


@pytest.fixture(params=[True, False])
def signed(request):
return request.param


@pytest.fixture(params=[lambda x: x, str], ids=["identity", "str"])
def transform(request):
return request.param


@pytest.fixture(params=[
47393996303418497800,
100000000000000000000
])
def large_val(request):
return request.param


@pytest.fixture(params=[True, False])
def multiple_elts(request):
return request.param


@pytest.fixture(params=[
(lambda x: Index(x, name="idx"), tm.assert_index_equal),
(lambda x: Series(x, name="ser"), tm.assert_series_equal),
(lambda x: np.array(Index(x).values), tm.assert_numpy_array_equal)
])
def transform_assert_equal(request):
return request.param


@pytest.mark.parametrize("input_kwargs,result_kwargs", [
(dict(), dict(dtype=np.int64)),
(dict(errors="coerce", downcast="integer"), dict(dtype=np.int8))
Expand Down Expand Up @@ -174,11 +211,6 @@ def test_all_nan():
tm.assert_series_equal(result, expected)


@pytest.fixture(params=[None, "ignore", "raise", "coerce"])
def errors(request):
return request.param


def test_type_check(errors):
# see gh-11776
df = DataFrame({"a": [1, -3.14, 7], "b": ["4", "5", "6"]})
Expand All @@ -189,30 +221,12 @@ def test_type_check(errors):
to_numeric(df, **kwargs)


@pytest.fixture(params=[True, False])
def signed(request):
return request.param


@pytest.fixture(params=[lambda x: x, str], ids=["identity", "str"])
def transform(request):
return request.param


@pytest.mark.parametrize("val", [1, 1.1, 20001])
def test_scalar(val, signed, transform):
val = -val if signed else val
assert to_numeric(transform(val)) == float(val)


@pytest.fixture(params=[
47393996303418497800,
100000000000000000000
])
def large_val(request):
return request.param


def test_really_large_scalar(large_val, signed, transform, errors):
# see gh-24910
kwargs = dict(errors=errors) if errors is not None else dict()
Expand All @@ -231,11 +245,6 @@ def test_really_large_scalar(large_val, signed, transform, errors):
assert tm.assert_almost_equal(to_numeric(val, **kwargs), expected)


@pytest.fixture(params=[True, False])
def multiple_elts(request):
return request.param


def test_really_large_in_arr(large_val, signed, transform,
multiple_elts, errors):
# see gh-24910
Expand Down Expand Up @@ -323,15 +332,6 @@ def test_scalar_fail(errors, checker):
assert checker(to_numeric(scalar, errors=errors))


@pytest.fixture(params=[
(lambda x: Index(x, name="idx"), tm.assert_index_equal),
(lambda x: Series(x, name="ser"), tm.assert_series_equal),
(lambda x: np.array(Index(x).values), tm.assert_numpy_array_equal)
])
def transform_assert_equal(request):
return request.param


@pytest.mark.parametrize("data", [
[1, 2, 3],
[1., np.nan, 3, np.nan]
Expand Down

0 comments on commit 1579b3f

Please sign in to comment.