Skip to content

Commit 945a74a

Browse files
committed
DEPR: move NumericIndex._format_native_types to Index
1 parent 77afbcc commit 945a74a

File tree

2 files changed

+20
-35
lines changed

2 files changed

+20
-35
lines changed

pandas/core/indexes/base.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,11 +1294,29 @@ def _format_with_header(self, header: list[str_t], na_rep: str_t) -> list[str_t]
12941294
return header + result
12951295

12961296
def _format_native_types(
1297-
self, *, na_rep: str_t = "", quoting=None, **kwargs
1297+
self,
1298+
*,
1299+
na_rep: str_t = "",
1300+
decimal: str = ".",
1301+
float_format=None,
1302+
quoting=None,
12981303
) -> npt.NDArray[np.object_]:
12991304
"""
13001305
Actually format specific types of the index.
13011306
"""
1307+
from pandas.io.formats.format import FloatArrayFormatter
1308+
1309+
if is_float_dtype(self.dtype) and not is_extension_array_dtype(self.dtype):
1310+
formatter = FloatArrayFormatter(
1311+
self._values,
1312+
na_rep=na_rep,
1313+
float_format=float_format,
1314+
decimal=decimal,
1315+
quoting=quoting,
1316+
fixed_width=False,
1317+
)
1318+
return formatter.get_result_as_array()
1319+
13021320
mask = isna(self)
13031321
if not self.is_object() and not quoting:
13041322
values = np.asarray(self).astype(str)

pandas/core/indexes/numeric.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
index as libindex,
1212
lib,
1313
)
14-
from pandas._typing import (
15-
Dtype,
16-
npt,
17-
)
14+
from pandas._typing import Dtype
1815
from pandas.util._decorators import (
1916
cache_readonly,
2017
doc,
@@ -279,36 +276,6 @@ def _assert_safe_casting(cls, data: np.ndarray, subarr: np.ndarray) -> None:
279276
if not np.array_equal(data, subarr):
280277
raise TypeError("Unsafe NumPy casting, you must explicitly cast")
281278

282-
def _format_native_types(
283-
self,
284-
*,
285-
na_rep: str = "",
286-
float_format=None,
287-
decimal: str = ".",
288-
quoting=None,
289-
**kwargs,
290-
) -> npt.NDArray[np.object_]:
291-
from pandas.io.formats.format import FloatArrayFormatter
292-
293-
if is_float_dtype(self.dtype):
294-
formatter = FloatArrayFormatter(
295-
self._values,
296-
na_rep=na_rep,
297-
float_format=float_format,
298-
decimal=decimal,
299-
quoting=quoting,
300-
fixed_width=False,
301-
)
302-
return formatter.get_result_as_array()
303-
304-
return super()._format_native_types(
305-
na_rep=na_rep,
306-
float_format=float_format,
307-
decimal=decimal,
308-
quoting=quoting,
309-
**kwargs,
310-
)
311-
312279

313280
_num_index_shared_docs = {}
314281

0 commit comments

Comments
 (0)