Skip to content

Commit ef6c35c

Browse files
authored
DEPR: move NumericIndex._format_native_types to Index (#50931)
* DEPR: move NumericIndex._format_native_types to Index * fix date_format parameter * fix mypy issue
1 parent 1c17d94 commit ef6c35c

File tree

2 files changed

+21
-35
lines changed

2 files changed

+21
-35
lines changed

pandas/core/indexes/base.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1291,11 +1291,30 @@ def _format_with_header(self, header: list[str_t], na_rep: str_t) -> list[str_t]
12911291
return header + result
12921292

12931293
def _format_native_types(
1294-
self, *, na_rep: str_t = "", quoting=None, **kwargs
1294+
self,
1295+
*,
1296+
na_rep: str_t = "",
1297+
decimal: str_t = ".",
1298+
float_format=None,
1299+
date_format=None,
1300+
quoting=None,
12951301
) -> npt.NDArray[np.object_]:
12961302
"""
12971303
Actually format specific types of the index.
12981304
"""
1305+
from pandas.io.formats.format import FloatArrayFormatter
1306+
1307+
if is_float_dtype(self.dtype) and not is_extension_array_dtype(self.dtype):
1308+
formatter = FloatArrayFormatter(
1309+
self._values,
1310+
na_rep=na_rep,
1311+
float_format=float_format,
1312+
decimal=decimal,
1313+
quoting=quoting,
1314+
fixed_width=False,
1315+
)
1316+
return formatter.get_result_as_array()
1317+
12991318
mask = isna(self)
13001319
if not self.is_object() and not quoting:
13011320
values = np.asarray(self).astype(str)

pandas/core/indexes/numeric.py

+1-34
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import numpy as np
66

77
from pandas._libs import index as libindex
8-
from pandas._typing import (
9-
Dtype,
10-
npt,
11-
)
8+
from pandas._typing import Dtype
129
from pandas.util._decorators import (
1310
cache_readonly,
1411
doc,
@@ -251,33 +248,3 @@ def _assert_safe_casting(cls, data: np.ndarray, subarr: np.ndarray) -> None:
251248
if is_integer_dtype(subarr.dtype):
252249
if not np.array_equal(data, subarr):
253250
raise TypeError("Unsafe NumPy casting, you must explicitly cast")
254-
255-
def _format_native_types(
256-
self,
257-
*,
258-
na_rep: str = "",
259-
float_format=None,
260-
decimal: str = ".",
261-
quoting=None,
262-
**kwargs,
263-
) -> npt.NDArray[np.object_]:
264-
from pandas.io.formats.format import FloatArrayFormatter
265-
266-
if is_float_dtype(self.dtype):
267-
formatter = FloatArrayFormatter(
268-
self._values,
269-
na_rep=na_rep,
270-
float_format=float_format,
271-
decimal=decimal,
272-
quoting=quoting,
273-
fixed_width=False,
274-
)
275-
return formatter.get_result_as_array()
276-
277-
return super()._format_native_types(
278-
na_rep=na_rep,
279-
float_format=float_format,
280-
decimal=decimal,
281-
quoting=quoting,
282-
**kwargs,
283-
)

0 commit comments

Comments
 (0)