From 777864d3be43303bf82f45aab3082bf16b5dae04 Mon Sep 17 00:00:00 2001 From: Horace Lai Date: Sun, 8 Aug 2021 20:41:32 +0000 Subject: [PATCH 1/6] TST: add test for getting array from series --- pandas/tests/test_constructors.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 pandas/tests/test_constructors.py diff --git a/pandas/tests/test_constructors.py b/pandas/tests/test_constructors.py new file mode 100644 index 0000000000000..5603a2b854f47 --- /dev/null +++ b/pandas/tests/test_constructors.py @@ -0,0 +1,18 @@ +import numpy as np +import pytest + +import pandas as pd +import pandas._testing as tm + + +@pytest.mark.parametrize( + "input_dict,expected", + [ + ({0: 0}, np.array([[0]], dtype=int)), + ({"a": "a"}, np.array([["a"]], dtype=object)), + ({1: 1}, np.array([[1]], dtype=int)), + ], +) +def test_numpy_array(input_dict, expected): + result = np.array([pd.Series(input_dict)]) + tm.assert_numpy_array_equal(result, expected) From a74d8a00f4ed45922d8c5bceaa9e33d165270abe Mon Sep 17 00:00:00 2001 From: Horace Lai Date: Sun, 22 Aug 2021 02:14:03 +0000 Subject: [PATCH 2/6] TST: add test for getting array from series --- pandas/tests/series/test_constructors.py | 13 +++++++++++++ pandas/tests/test_constructors.py | 18 ------------------ 2 files changed, 13 insertions(+), 18 deletions(-) delete mode 100644 pandas/tests/test_constructors.py diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 8525edc8dee80..361cb6f2ad719 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1827,3 +1827,16 @@ def test_constructor(rand_series_with_duplicate_datetimeindex): dups = rand_series_with_duplicate_datetimeindex assert isinstance(dups, Series) assert isinstance(dups.index, DatetimeIndex) + + +@pytest.mark.parametrize( + "input_dict,expected", + [ + ({0: 0}, np.array([[0]], dtype=int)), + ({"a": "a"}, np.array([["a"]], dtype=object)), + ({1: 1}, np.array([[1]], dtype=int)), + ], +) +def test_numpy_array(input_dict, expected): + result = np.array([Series(input_dict)]) + tm.assert_numpy_array_equal(result, expected) diff --git a/pandas/tests/test_constructors.py b/pandas/tests/test_constructors.py deleted file mode 100644 index 5603a2b854f47..0000000000000 --- a/pandas/tests/test_constructors.py +++ /dev/null @@ -1,18 +0,0 @@ -import numpy as np -import pytest - -import pandas as pd -import pandas._testing as tm - - -@pytest.mark.parametrize( - "input_dict,expected", - [ - ({0: 0}, np.array([[0]], dtype=int)), - ({"a": "a"}, np.array([["a"]], dtype=object)), - ({1: 1}, np.array([[1]], dtype=int)), - ], -) -def test_numpy_array(input_dict, expected): - result = np.array([pd.Series(input_dict)]) - tm.assert_numpy_array_equal(result, expected) From f4c4f3b961eab335a0137320ea6f00309967c931 Mon Sep 17 00:00:00 2001 From: Horace Lai Date: Sun, 5 Sep 2021 20:53:20 +0000 Subject: [PATCH 3/6] add skipif for low versions of numpy --- pandas/tests/series/test_constructors.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index ea9a486c74f65..1da092155e3aa 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -13,6 +13,7 @@ iNaT, lib, ) +from pandas.compat.numpy import np_version_under1p19 import pandas.util._test_decorators as td from pandas.core.dtypes.common import ( @@ -1850,6 +1851,7 @@ def test_constructor(rand_series_with_duplicate_datetimeindex): ({1: 1}, np.array([[1]], dtype=int)), ], ) +@pytest.mark.skipif(np_version_under1p19, reason="fails on numpy below 1.19") def test_numpy_array(input_dict, expected): result = np.array([Series(input_dict)]) tm.assert_numpy_array_equal(result, expected) From 3e70ff1f97b5f2084e2e25415084dc0b395c6c46 Mon Sep 17 00:00:00 2001 From: Horace Lai Date: Mon, 6 Sep 2021 08:05:13 +0000 Subject: [PATCH 4/6] add dtype np.int64 --- pandas/tests/series/test_constructors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 1da092155e3aa..686c9ecb9d071 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1846,9 +1846,9 @@ def test_constructor(rand_series_with_duplicate_datetimeindex): @pytest.mark.parametrize( "input_dict,expected", [ - ({0: 0}, np.array([[0]], dtype=int)), + ({0: 0}, np.array([[0]], dtype=np.int64)), ({"a": "a"}, np.array([["a"]], dtype=object)), - ({1: 1}, np.array([[1]], dtype=int)), + ({1: 1}, np.array([[1]], dtype=np.int64)), ], ) @pytest.mark.skipif(np_version_under1p19, reason="fails on numpy below 1.19") From 89f6dd77edd412d4b4921af26e1be65e9ad884cf Mon Sep 17 00:00:00 2001 From: Horace Lai Date: Mon, 6 Sep 2021 21:01:40 +0000 Subject: [PATCH 5/6] add test to check that exception is raised for np version < 1.19 --- pandas/tests/series/test_constructors.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 686c9ecb9d071..9644837260d50 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1855,3 +1855,11 @@ def test_constructor(rand_series_with_duplicate_datetimeindex): def test_numpy_array(input_dict, expected): result = np.array([Series(input_dict)]) tm.assert_numpy_array_equal(result, expected) + + +@pytest.mark.skipif( + not np_version_under1p19, reason="check failure on numpy below 1.19" +) +def test_numpy_array_np_v1p19(): + with pytest.raises(KeyError, match="KeyError: 0"): + np.array([Series({1: 1})]) From 5d620d35e81d19db69162dd06855270f01c7d993 Mon Sep 17 00:00:00 2001 From: Horace Lai Date: Sun, 12 Sep 2021 19:09:06 +0000 Subject: [PATCH 6/6] change matched string to '0' --- pandas/tests/series/test_constructors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 9644837260d50..dbf6d5627c00b 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -1861,5 +1861,5 @@ def test_numpy_array(input_dict, expected): not np_version_under1p19, reason="check failure on numpy below 1.19" ) def test_numpy_array_np_v1p19(): - with pytest.raises(KeyError, match="KeyError: 0"): + with pytest.raises(KeyError, match="0"): np.array([Series({1: 1})])