Skip to content

Commit a54aa39

Browse files
authored
TST: add test for getting array from series (pandas-dev#42939)
* TST: add test for getting array from series * TST: add test for getting array from series * add skipif for low versions of numpy * add dtype np.int64 * add test to check that exception is raised for np version < 1.19 * change matched string to '0'
1 parent 02fdbde commit a54aa39

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pandas/tests/series/test_constructors.py

+23
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
iNaT,
1414
lib,
1515
)
16+
from pandas.compat.numpy import np_version_under1p19
1617
import pandas.util._test_decorators as td
1718

1819
from pandas.core.dtypes.common import (
@@ -1840,3 +1841,25 @@ def test_constructor(rand_series_with_duplicate_datetimeindex):
18401841
dups = rand_series_with_duplicate_datetimeindex
18411842
assert isinstance(dups, Series)
18421843
assert isinstance(dups.index, DatetimeIndex)
1844+
1845+
1846+
@pytest.mark.parametrize(
1847+
"input_dict,expected",
1848+
[
1849+
({0: 0}, np.array([[0]], dtype=np.int64)),
1850+
({"a": "a"}, np.array([["a"]], dtype=object)),
1851+
({1: 1}, np.array([[1]], dtype=np.int64)),
1852+
],
1853+
)
1854+
@pytest.mark.skipif(np_version_under1p19, reason="fails on numpy below 1.19")
1855+
def test_numpy_array(input_dict, expected):
1856+
result = np.array([Series(input_dict)])
1857+
tm.assert_numpy_array_equal(result, expected)
1858+
1859+
1860+
@pytest.mark.skipif(
1861+
not np_version_under1p19, reason="check failure on numpy below 1.19"
1862+
)
1863+
def test_numpy_array_np_v1p19():
1864+
with pytest.raises(KeyError, match="0"):
1865+
np.array([Series({1: 1})])

0 commit comments

Comments
 (0)