Skip to content

Commit 55cb505

Browse files
author
Jiang Yue
committed
add whatsnew and make required changes
1 parent 514a7c0 commit 55cb505

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ Other API changes
825825
- :meth:`ExtensionArray.argsort` places NA values at the end of the sorted array. (:issue:`21801`)
826826
- :meth:`DataFrame.to_hdf` and :meth:`Series.to_hdf` will now raise a ``NotImplementedError`` when saving a :class:`MultiIndex` with extention data types for a ``fixed`` format. (:issue:`7775`)
827827
- Passing duplicate ``names`` in :meth:`read_csv` will now raise a ``ValueError`` (:issue:`17346`)
828+
- :meth:`infer_type` will now return integer-na for integer and np.nan mix (:issue:`27283`)
828829
829830
.. _whatsnew_0250.deprecations:
830831

pandas/_libs/lib.pyx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1519,10 +1519,8 @@ cpdef bint is_integer_array(ndarray values):
15191519

15201520
cdef class IntegerNaValidator(Validator):
15211521
cdef inline bint is_value_typed(self, object value) except -1:
1522-
return util.is_integer_object(value) or util.is_nan(value)
1523-
1524-
cdef inline bint is_array_typed(self) except -1:
1525-
return issubclass(self.dtype.type, np.integer)
1522+
return util.is_integer_object(value) or (util.is_nan(value)
1523+
and util.is_float_object(value))
15261524

15271525

15281526
cdef bint is_integer_na_array(ndarray values):

pandas/core/indexes/base.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ def __new__(
473473

474474
return Index(subarr, copy=copy, dtype=object, name=name)
475475
elif inferred in ["floating", "mixed-integer-float", "integer-na"]:
476+
# TODO: Returns IntegerArray for integer-na case in the future
476477
from .numeric import Float64Index
477478

478479
return Float64Index(subarr, copy=copy, name=name)
@@ -3197,10 +3198,7 @@ def is_int(v):
31973198
self.get_loc(stop)
31983199
is_positional = False
31993200
except KeyError:
3200-
if (
3201-
self.inferred_type == "mixed-integer-float"
3202-
or self.inferred_type == "integer-na"
3203-
):
3201+
if self.inferred_type in ["mixed-integer-float", "integer-na"]:
32043202
raise
32053203

32063204
if is_null_slicer:

pandas/tests/dtypes/test_inference.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,17 @@ def test_integers(self):
577577
result = lib.infer_dtype(arr, skipna=True)
578578
assert result == "integer"
579579

580-
# GH 27392
581-
def test_integer_na(self):
580+
@pytest.mark.parametrize("skipna", [True, False])
581+
def test_integer_na(self, skipna):
582+
# GH 27392
583+
expected = "integer" if skipna else "integer-na"
582584
arr = np.array([1, 2, np.nan, np.nan, 3], dtype="O")
583-
result = lib.infer_dtype(arr, skipna=False)
584-
assert result == "integer-na"
585+
result = lib.infer_dtype(arr, skipna=skipna)
586+
assert result == expected
585587

586588
arr = np.array([1, 2, 3, np.int64(4), np.int32(5), np.nan], dtype="O")
587-
result = lib.infer_dtype(arr, skipna=False)
588-
assert result == "integer-na"
589+
result = lib.infer_dtype(arr, skipna=skipna)
590+
assert result == expected
589591

590592
def test_deprecation(self):
591593
# GH 24050

0 commit comments

Comments
 (0)