Skip to content

Commit bc15e85

Browse files
committed
ENH: Add the decimal.Decimal type to infer_dtypes (pandas-dev#15690)
1 parent d5a681b commit bc15e85

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pandas/_libs/src/inference.pyx

+3-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ def infer_dtype(object value):
308308
'categorical'
309309
310310
"""
311-
312311
cdef:
313312
Py_ssize_t i, n
314313
object val
@@ -407,6 +406,9 @@ def infer_dtype(object value):
407406
if is_time_array(values):
408407
return 'time'
409408

409+
elif is_decimal(val):
410+
return 'decimal'
411+
410412
elif util.is_float_object(val):
411413
if is_float_array(values):
412414
return 'floating'

pandas/tests/dtypes/test_inference.py

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import collections
1010
import re
1111
from datetime import datetime, date, timedelta, time
12+
from decimal import Decimal
1213
import numpy as np
1314
import pytz
1415
import pytest
@@ -462,6 +463,11 @@ def test_floats(self):
462463
result = lib.infer_dtype(arr)
463464
assert result == 'floating'
464465

466+
def test_decimals(self):
467+
arr = np.array([Decimal(1), Decimal(2), Decimal(3)])
468+
result = lib.infer_dtype(arr)
469+
assert result == 'decimal'
470+
465471
def test_string(self):
466472
pass
467473

0 commit comments

Comments
 (0)