Skip to content

Commit 138b8ba

Browse files
jseaboldjreback
authored andcommitted
BUG: Let numpy typecodes pass through. Closes #11990
TST: Failing test for numpy typecode select BUG: Let numpy typecodes pass through. DOC: Document bug fix STY: Formatting
1 parent b641685 commit 138b8ba

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/source/whatsnew/v0.18.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Other enhancements
117117
values it contains (:issue:`11597`)
118118
- ``Series`` gained an ``is_unique`` attribute (:issue:`11946`)
119119
- ``DataFrame.quantile`` and ``Series.quantile`` now accept ``interpolation`` keyword (:issue:`10174`).
120+
- ``DataFrame.select_dtypes`` now allows the ``np.float16`` typecode (:issue:`11990`)
120121

121122
.. _whatsnew_0180.enhancements.rounding:
122123

pandas/core/common.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1481,11 +1481,12 @@ def _get_dtype_from_object(dtype):
14811481
dtype += '64'
14821482

14831483
try:
1484-
return _get_dtype_from_object(getattr(np,dtype))
1485-
except AttributeError:
1484+
return _get_dtype_from_object(getattr(np, dtype))
1485+
except (AttributeError, TypeError):
14861486
# handles cases like _get_dtype(int)
14871487
# i.e., python objects that are valid dtypes (unlike user-defined
14881488
# types, in general)
1489+
# TypeError handles the float16 typecode of 'e'
14891490
# further handle internal types
14901491
pass
14911492

pandas/tests/test_frame.py

+7
Original file line numberDiff line numberDiff line change
@@ -16029,6 +16029,13 @@ def test_select_dtypes_bad_arg_raises(self):
1602916029
with tm.assertRaisesRegexp(TypeError, 'data type.*not understood'):
1603016030
df.select_dtypes(['blargy, blarg, blarg'])
1603116031

16032+
def test_select_dtypes_typecodes(self):
16033+
# GH 11990
16034+
df = mkdf(30, 3, data_gen_f=lambda x, y: np.random.random())
16035+
expected = df
16036+
FLOAT_TYPES = list(np.typecodes['AllFloat'])
16037+
assert_frame_equal(df.select_dtypes(FLOAT_TYPES), expected)
16038+
1603216039
def test_assign(self):
1603316040
df = DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
1603416041
original = df.copy()

0 commit comments

Comments
 (0)