Skip to content

Commit 737ea96

Browse files
committed
complex 64 and 128 testing
1 parent 1d11a90 commit 737ea96

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

pandas/tests/reductions/test_reductions.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,3 +1487,33 @@ def test_mode_boolean_with_na(self):
14871487
result = ser.mode()
14881488
expected = Series({0: True}, dtype="boolean")
14891489
tm.assert_series_equal(result, expected)
1490+
1491+
@pytest.mark.parametrize(
1492+
"array,expected,dtype",
1493+
[
1494+
([0, 1j, 1, 1, 1 + 1j, 1 + 2j], Series([1], dtype=np.complex128), np.complex128),
1495+
([0, 1j, 1, 1, 1 + 1j, 1 + 2j], Series([1], dtype=np.complex64), np.complex64),
1496+
([1 + 1j, 2j, 1 + 1j], Series([1 + 1j], dtype=np.complex128), np.complex128),
1497+
],
1498+
)
1499+
def test_unimode_complex(self, array, expected, dtype):
1500+
result = Series(array, dtype=dtype).mode()
1501+
tm.assert_series_equal(result, expected)
1502+
1503+
@pytest.mark.parametrize(
1504+
"array,expected,dtype",
1505+
[
1506+
(
1507+
# no modes
1508+
[0, 1j, 1, 1 + 1j, 1 + 2j],
1509+
Series([0j, 1j, 1 + 0j, 1 + 1j, 1 + 2j], dtype=np.complex128),
1510+
np.complex128
1511+
),
1512+
([1 + 1j, 2j, 1 + 1j, 2j, 3], Series([2j, 1 + 1j], dtype=np.complex64), np.complex64),
1513+
],
1514+
)
1515+
def test_multimode_complex(self, array, expected,dtype):
1516+
# mode tries to sort multimodal series.
1517+
# Complex numbers are sorted by their magnitude
1518+
result = Series(array, dtype=dtype).mode()
1519+
tm.assert_series_equal(result, expected)

pandas/tests/series/methods/test_value_counts.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,25 @@ def test_value_counts_bool_with_nan(self, ser, dropna, exp):
209209
tm.assert_series_equal(out, exp)
210210

211211
@pytest.mark.parametrize(
212-
"input_array,expected",
212+
"input_array,expected,dtype",
213213
[
214214
(
215215
[1 + 1j, 0, 1 + 0j, 1j, 1 + 2j],
216216
Series([1, 1, 1, 1, 1], index=[0, 1 + 0j, 1j, 1 + 1j, 1 + 2j]),
217+
np.complex128
217218
),
218219
(
219220
[1 + 2j, 0, 1j, 1, 1j, 1 + 1j, 1 + 1j],
220-
# index is sorted by value counts in descending order by default
221221
Series([2, 1, 1, 2, 1], index=pd.Index([1j, 0, 1, 1 + 1j, 1 + 2j], dtype=np.complex128)),
222+
np.complex128
223+
),
224+
(
225+
[1 + 2j, 0, 1j, 1, 1j, 1 + 1j, 1 + 1j],
226+
Series([2, 1, 1, 2, 1], index=pd.Index([1j, 0, 1, 1 + 1j, 1 + 2j], dtype=np.complex64)),
227+
np.complex64
222228
),
223229
],
224230
)
225-
def test_value_counts_complex_numbers(self, input_array, expected):
226-
result = pd.Series(input_array, dtype=np.complex128).value_counts()
231+
def test_value_counts_complex_numbers(self, input_array, expected, dtype):
232+
result = pd.Series(input_array, dtype=dtype).value_counts()
227233
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)