Skip to content

Commit 05406dc

Browse files
author
OlehKSS
committed
Fix select_dtypes(include='int') for Windows.
1 parent 6fc17fa commit 05406dc

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

pandas/core/dtypes/common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,11 @@ def pandas_dtype(dtype) -> DtypeObj:
17961796
# try a numpy dtype
17971797
# raise a consistent TypeError if failed
17981798
try:
1799+
# int is mapped to different types (int32, in64) on Windows and Linux
1800+
# see https://github.com/numpy/numpy/issues/9464
1801+
if (isinstance(dtype, str) and dtype == "int") or (dtype is int):
1802+
dtype = "int64"
1803+
17991804
npdtype = np.dtype(dtype)
18001805
except SyntaxError as err:
18011806
# np.dtype uses `eval` which can raise SyntaxError

pandas/tests/dtypes/test_common.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,22 @@ def test_invalid_dtype_error(self, box):
4343
com.pandas_dtype(box)
4444

4545
@pytest.mark.parametrize(
46-
"dtype",
46+
"dtype_input,dtype_output",
4747
[
48-
object,
49-
"float64",
50-
np.object_,
51-
np.dtype("object"),
52-
"O",
53-
np.float64,
54-
float,
55-
np.dtype("float64"),
48+
(object, object),
49+
("float64", np.float64),
50+
(np.object_, np.object_),
51+
(np.dtype("object"), np.object_),
52+
("O", object),
53+
(np.float64, np.float64),
54+
(float, float),
55+
(np.dtype("float64"), np.float64),
56+
("int", np.int64),
57+
(int, np.int64)
5658
],
5759
)
58-
def test_pandas_dtype_valid(self, dtype):
59-
assert com.pandas_dtype(dtype) == dtype
60+
def test_pandas_dtype_valid(self, dtype_input, dtype_output):
61+
assert com.pandas_dtype(dtype_input) == dtype_output
6062

6163
@pytest.mark.parametrize(
6264
"dtype", ["M8[ns]", "m8[ns]", "object", "float64", "int64"]

pandas/tests/frame/methods/test_select_dtypes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ def test_select_dtypes_exclude_include_using_list_like(self):
8282
e = df[["b", "c", "e"]]
8383
tm.assert_frame_equal(r, e)
8484

85+
exclude = (np.datetime64,)
86+
include = np.bool_, "int"
87+
r = df.select_dtypes(include=include, exclude=exclude)
88+
e = df[["b", "e"]]
89+
tm.assert_frame_equal(r, e)
90+
8591
exclude = ("datetime",)
8692
include = "bool", "int64", "int32"
8793
r = df.select_dtypes(include=include, exclude=exclude)

0 commit comments

Comments
 (0)