Skip to content

Commit 74516a8

Browse files
committed
CLN: Remove downcast_int64 from inference.pyx
It was only being used for the compact_ints and use_unsigned parameters in read_csv.
1 parent af7fc60 commit 74516a8

File tree

2 files changed

+0
-107
lines changed

2 files changed

+0
-107
lines changed

pandas/_libs/src/inference.pyx

-71
Original file line numberDiff line numberDiff line change
@@ -1657,74 +1657,3 @@ def fast_multiget(dict mapping, ndarray keys, default=np.nan):
16571657
output[i] = default
16581658

16591659
return maybe_convert_objects(output)
1660-
1661-
1662-
def downcast_int64(ndarray[int64_t] arr, object na_values,
1663-
bint use_unsigned=0):
1664-
cdef:
1665-
Py_ssize_t i, n = len(arr)
1666-
int64_t mx = INT64_MIN + 1, mn = INT64_MAX
1667-
int64_t NA = na_values[np.int64]
1668-
int64_t val
1669-
ndarray[uint8_t] mask
1670-
int na_count = 0
1671-
1672-
_mask = np.empty(n, dtype=bool)
1673-
mask = _mask.view(np.uint8)
1674-
1675-
for i in range(n):
1676-
val = arr[i]
1677-
1678-
if val == NA:
1679-
mask[i] = 1
1680-
na_count += 1
1681-
continue
1682-
1683-
# not NA
1684-
mask[i] = 0
1685-
1686-
if val > mx:
1687-
mx = val
1688-
1689-
if val < mn:
1690-
mn = val
1691-
1692-
if mn >= 0 and use_unsigned:
1693-
if mx <= UINT8_MAX - 1:
1694-
result = arr.astype(np.uint8)
1695-
if na_count:
1696-
np.putmask(result, _mask, na_values[np.uint8])
1697-
return result
1698-
1699-
if mx <= UINT16_MAX - 1:
1700-
result = arr.astype(np.uint16)
1701-
if na_count:
1702-
np.putmask(result, _mask, na_values[np.uint16])
1703-
return result
1704-
1705-
if mx <= UINT32_MAX - 1:
1706-
result = arr.astype(np.uint32)
1707-
if na_count:
1708-
np.putmask(result, _mask, na_values[np.uint32])
1709-
return result
1710-
1711-
else:
1712-
if mn >= INT8_MIN + 1 and mx <= INT8_MAX:
1713-
result = arr.astype(np.int8)
1714-
if na_count:
1715-
np.putmask(result, _mask, na_values[np.int8])
1716-
return result
1717-
1718-
if mn >= INT16_MIN + 1 and mx <= INT16_MAX:
1719-
result = arr.astype(np.int16)
1720-
if na_count:
1721-
np.putmask(result, _mask, na_values[np.int16])
1722-
return result
1723-
1724-
if mn >= INT32_MIN + 1 and mx <= INT32_MAX:
1725-
result = arr.astype(np.int32)
1726-
if na_count:
1727-
np.putmask(result, _mask, na_values[np.int32])
1728-
return result
1729-
1730-
return arr

pandas/tests/dtypes/test_io.py

-36
Original file line numberDiff line numberDiff line change
@@ -71,39 +71,3 @@ def test_convert_sql_column_decimals(self):
7171
result = lib.convert_sql_column(arr)
7272
expected = np.array([1.5, np.nan, 3, 4.2], dtype='f8')
7373
tm.assert_numpy_array_equal(result, expected)
74-
75-
def test_convert_downcast_int64(self):
76-
from pandas._libs.parsers import na_values
77-
78-
arr = np.array([1, 2, 7, 8, 10], dtype=np.int64)
79-
expected = np.array([1, 2, 7, 8, 10], dtype=np.int8)
80-
81-
# default argument
82-
result = lib.downcast_int64(arr, na_values)
83-
tm.assert_numpy_array_equal(result, expected)
84-
85-
result = lib.downcast_int64(arr, na_values, use_unsigned=False)
86-
tm.assert_numpy_array_equal(result, expected)
87-
88-
expected = np.array([1, 2, 7, 8, 10], dtype=np.uint8)
89-
result = lib.downcast_int64(arr, na_values, use_unsigned=True)
90-
tm.assert_numpy_array_equal(result, expected)
91-
92-
# still cast to int8 despite use_unsigned=True
93-
# because of the negative number as an element
94-
arr = np.array([1, 2, -7, 8, 10], dtype=np.int64)
95-
expected = np.array([1, 2, -7, 8, 10], dtype=np.int8)
96-
result = lib.downcast_int64(arr, na_values, use_unsigned=True)
97-
tm.assert_numpy_array_equal(result, expected)
98-
99-
arr = np.array([1, 2, 7, 8, 300], dtype=np.int64)
100-
expected = np.array([1, 2, 7, 8, 300], dtype=np.int16)
101-
result = lib.downcast_int64(arr, na_values)
102-
tm.assert_numpy_array_equal(result, expected)
103-
104-
int8_na = na_values[np.int8]
105-
int64_na = na_values[np.int64]
106-
arr = np.array([int64_na, 2, 3, 10, 15], dtype=np.int64)
107-
expected = np.array([int8_na, 2, 3, 10, 15], dtype=np.int8)
108-
result = lib.downcast_int64(arr, na_values)
109-
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)