From 1579b3f0a7b713f4b0dd9b1fd951c7a43a812a53 Mon Sep 17 00:00:00 2001 From: gfyoung Date: Wed, 30 Jan 2019 14:10:03 -0800 Subject: [PATCH] MAINT: Address comments --- pandas/core/tools/numeric.py | 10 ++-- pandas/tests/tools/test_numeric.py | 74 +++++++++++++++--------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/pandas/core/tools/numeric.py b/pandas/core/tools/numeric.py index 84c2340fdc54a..24f3e6753e500 100644 --- a/pandas/core/tools/numeric.py +++ b/pandas/core/tools/numeric.py @@ -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 ---------- diff --git a/pandas/tests/tools/test_numeric.py b/pandas/tests/tools/test_numeric.py index 5fae422539284..97e1dc2f6aefc 100644 --- a/pandas/tests/tools/test_numeric.py +++ b/pandas/tests/tools/test_numeric.py @@ -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)) @@ -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"]}) @@ -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() @@ -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 @@ -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]