Skip to content

Commit 582099c

Browse files
committed
BUG: Let numpy typecodes pass through. Closes pandas-dev#11990
TST: Failing test for numpy typecode select BUG: Let numpy typecodes pass through. DOC: Document bug fix STY: Formatting
1 parent 44e4c96 commit 582099c

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v0.18.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Other enhancements
112112
values it contains (:issue:`11597`)
113113
- ``Series`` gained an ``is_unique`` attribute (:issue:`11946`)
114114
- ``DataFrame.quantile`` and ``Series.quantile`` now accept ``interpolation`` keyword (:issue:`10174`).
115+
- ``DataFrame.select_dtypes`` now allows the ``np.float16`` typecode (:issue:`11990`)
115116

116117
.. _whatsnew_0180.enhancements.rounding:
117118

pandas/core/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1482,10 +1482,11 @@ def _get_dtype_from_object(dtype):
14821482

14831483
try:
14841484
return _get_dtype_from_object(getattr(np,dtype))
1485-
except AttributeError:
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
@@ -16016,6 +16016,13 @@ def test_select_dtypes_bad_arg_raises(self):
1601616016
with tm.assertRaisesRegexp(TypeError, 'data type.*not understood'):
1601716017
df.select_dtypes(['blargy, blarg, blarg'])
1601816018

16019+
def test_select_dtypes_typecodes(self):
16020+
# GH 11990
16021+
df = mkdf(30, 3, data_gen_f=lambda x, y: np.random.random())
16022+
expected = df
16023+
FLOAT_TYPES = list(np.typecodes['AllFloat'])
16024+
assert_frame_equal(df.select_dtypes(FLOAT_TYPES), expected)
16025+
1601916026
def test_assign(self):
1602016027
df = DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
1602116028
original = df.copy()

0 commit comments

Comments
 (0)