Skip to content

Commit f6edfac

Browse files
Terji PetersenTerji Petersen
Terji Petersen
authored and
Terji Petersen
committed
fail on float16, but allow np.exp(int8_arrays) II
1 parent 93584ab commit f6edfac

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

pandas/core/algorithms.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,8 @@ def value_counts(
891891
else:
892892
values = _ensure_arraylike(values)
893893
keys, counts = value_counts_arraylike(values, dropna)
894+
if keys.dtype == np.float16:
895+
keys = keys.astype(np.float32)
894896

895897
# For backwards compatibility, we let Index do its normal type
896898
# inference, _except_ for if if infers from object to bool.

pandas/core/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,8 @@ def factorize(
11401140
codes, uniques = algorithms.factorize(
11411141
self._values, sort=sort, use_na_sentinel=use_na_sentinel
11421142
)
1143+
if uniques.dtype == np.float16:
1144+
uniques = uniques.astype(np.float32)
11431145

11441146
if isinstance(self, ABCIndex):
11451147
# preserve e.g. NumericIndex, preserve MultiIndex

pandas/tests/test_algos.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ def test_factorize(self, index_or_series_obj, sort):
6666
constructor = Index
6767
if isinstance(obj, MultiIndex):
6868
constructor = MultiIndex.from_tuples
69-
expected_uniques = constructor(obj.unique())
69+
expected_arr = obj.unique()
70+
if expected_arr.dtype == np.float16:
71+
expected_arr = expected_arr.astype(np.float32)
72+
expected_uniques = constructor(expected_arr)
7073
if (
7174
isinstance(obj, Index)
7275
and expected_uniques.dtype == bool

0 commit comments

Comments
 (0)