Skip to content

Commit 311106a

Browse files
committed
syntax changes
1 parent 7ecaf79 commit 311106a

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

pandas/core/reshape/tile.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
from pandas.core.dtypes.common import (
1212
_NS_DTYPE,
1313
ensure_int64,
14+
is_bool_dtype,
1415
is_categorical_dtype,
1516
is_datetime64_dtype,
1617
is_datetime64tz_dtype,
1718
is_datetime_or_timedelta_dtype,
1819
is_integer,
1920
is_scalar,
2021
is_timedelta64_dtype,
21-
is_bool_dtype
2222
)
2323
from pandas.core.dtypes.missing import isna
2424

@@ -439,12 +439,14 @@ def _coerce_to_type(x):
439439
x = to_timedelta(x)
440440
dtype = np.dtype("timedelta64[ns]")
441441
elif is_bool_dtype(x):
442-
x = x.astype(int)
443442
dtype = x.dtype
444443

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

449451
return x, dtype
450452

pandas/tests/reshape/test_cut.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,14 @@ def test_timedelta_cut_roundtrip():
588588

589589

590590
@pytest.mark.parametrize("bins", [6, 7])
591-
@pytest.mark.parametrize("box", "compare", [(Series, tm.assert_series_equal), (np.array,tm.assert_categorical_equal)])
591+
@pytest.mark.parametrize(
592+
"box, compare",
593+
[(Series, tm.assert_series_equal), (np.array, tm.assert_categorical_equal)],
594+
)
592595
def test_cut_bool_coercion_to_int(bins, box, compare):
593596
# issue 20303
594597
x = box(np.random.randint(2, size=200))
595-
expected = cut(x, bins, duplicates='drop')
598+
expected = cut(x, bins, duplicates="drop")
596599
data = x.astype(bool)
597-
result = cut(data, bins, duplicates='drop')
598-
compare(result, expected)
600+
result = cut(data, bins, duplicates="drop")
601+
compare(result, expected)

pandas/tests/reshape/test_qcut.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,16 @@ def test_date_like_qcut_bins(arg, expected_bins):
237237
result, result_bins = qcut(ser, 2, retbins=True)
238238
tm.assert_index_equal(result_bins, expected_bins)
239239

240+
240241
@pytest.mark.parametrize("bins", [6, 7])
241-
@pytest.mark.parametrize("box", "compare", [(Series, tm.assert_series_equal), (np.array,tm.assert_categorical_equal)])
242+
@pytest.mark.parametrize(
243+
"box, compare",
244+
[(Series, tm.assert_series_equal), (np.array, tm.assert_categorical_equal)],
245+
)
242246
def test_qcut_bool_coercion_to_int(bins, box, compare):
243247
# issue 20303
244248
x = box(np.random.randint(2, size=200))
245-
expected = qcut(x, bins, duplicates='drop')
249+
expected = qcut(x, bins, duplicates="drop")
246250
data = x.astype(bool)
247-
result = qcut(data, bins, duplicates='drop')
248-
compare(result, expected)
251+
result = qcut(data, bins, duplicates="drop")
252+
compare(result, expected)

0 commit comments

Comments
 (0)