Skip to content

Commit fd8aeb2

Browse files
author
OlehKSS
committed
Fix select_dtypes(include='int') for Windows.
1 parent 027f365 commit fd8aeb2

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

pandas/core/dtypes/common.py

+5
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,11 @@ def pandas_dtype(dtype) -> DtypeObj:
17911791
# try a numpy dtype
17921792
# raise a consistent TypeError if failed
17931793
try:
1794+
# int is mapped to different types (int32, in64) on Windows and Linux
1795+
# see https://github.com/numpy/numpy/issues/9464
1796+
if (isinstance(dtype, str) and dtype == "int") or (dtype is int):
1797+
dtype = "int64"
1798+
17941799
npdtype = np.dtype(dtype)
17951800
except SyntaxError as err:
17961801
# np.dtype uses `eval` which can raise SyntaxError

pandas/tests/dtypes/test_common.py

+13-11
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

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def test_select_dtypes_exclude_include_using_list_like(self):
8484
e = df[["b", "c", "e"]]
8585
tm.assert_frame_equal(r, e)
8686

87+
exclude = (np.datetime64,)
88+
include = np.bool_, "int"
89+
r = df.select_dtypes(include=include, exclude=exclude)
90+
e = df[["b", "e"]]
91+
tm.assert_frame_equal(r, e)
92+
8793
exclude = ("datetime",)
8894
include = "bool", "int64", "int32"
8995
r = df.select_dtypes(include=include, exclude=exclude)

0 commit comments

Comments
 (0)