Skip to content

Commit 412f2d9

Browse files
committed
Add list as box to tests and make more verbose
1 parent 33c889c commit 412f2d9

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

pandas/core/reshape/tile.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -439,14 +439,11 @@ def _coerce_to_type(x):
439439
x = to_timedelta(x)
440440
dtype = np.dtype("timedelta64[ns]")
441441
elif is_bool_dtype(x):
442-
dtype = x.dtype
442+
x = x.astype(np.int64)
443443

444444
if dtype is not None:
445445
# GH 19768: force NaT to NaN during integer conversion
446-
if is_bool_dtype(x):
447-
x = np.where(~np.isnan(x), x.astype(int), np.nan)
448-
else:
449-
x = np.where(x.notna(), x.view(np.int64), np.nan)
446+
x = np.where(x.notna(), x.view(np.int64), np.nan)
450447

451448
return x, dtype
452449

pandas/tests/reshape/test_cut.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,16 @@ def test_timedelta_cut_roundtrip():
590590
@pytest.mark.parametrize("bins", [6, 7])
591591
@pytest.mark.parametrize(
592592
"box, compare",
593-
[(Series, tm.assert_series_equal), (np.array, tm.assert_categorical_equal)],
593+
[
594+
(Series, tm.assert_series_equal),
595+
(np.array, tm.assert_categorical_equal),
596+
(list, tm.assert_equal),
597+
],
594598
)
595599
def test_cut_bool_coercion_to_int(bins, box, compare):
596600
# issue 20303
597-
x = box(np.random.randint(2, size=200))
598-
expected = cut(x, bins, duplicates="drop")
599-
data = x.astype(bool)
600-
result = cut(data, bins, duplicates="drop")
601+
data_expected = box([0, 1, 1, 0, 1] * 10)
602+
data_result = box([False, True, True, False, True] * 10)
603+
expected = cut(data_expected, bins, duplicates="drop")
604+
result = cut(data_result, bins, duplicates="drop")
601605
compare(result, expected)

pandas/tests/reshape/test_qcut.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,16 @@ def test_date_like_qcut_bins(arg, expected_bins):
241241
@pytest.mark.parametrize("bins", [6, 7])
242242
@pytest.mark.parametrize(
243243
"box, compare",
244-
[(Series, tm.assert_series_equal), (np.array, tm.assert_categorical_equal)],
244+
[
245+
(Series, tm.assert_series_equal),
246+
(np.array, tm.assert_categorical_equal),
247+
(list, tm.assert_equal),
248+
],
245249
)
246250
def test_qcut_bool_coercion_to_int(bins, box, compare):
247251
# issue 20303
248-
x = box(np.random.randint(2, size=200))
249-
expected = qcut(x, bins, duplicates="drop")
250-
data = x.astype(bool)
251-
result = qcut(data, bins, duplicates="drop")
252+
data_expected = box([0, 1, 1, 0, 1] * 10)
253+
data_result = box([False, True, True, False, True] * 10)
254+
expected = qcut(data_expected, bins, duplicates="drop")
255+
result = qcut(data_result, bins, duplicates="drop")
252256
compare(result, expected)

0 commit comments

Comments
 (0)