Skip to content

Commit c8aeb70

Browse files
simonjayhawkinsquintusdias
authored andcommitted
DEPR: Removed the previously deprecated ExtensionArray._formatting_values (pandas-dev#27774)
1 parent 575ac7a commit c8aeb70

File tree

9 files changed

+8
-90
lines changed

9 files changed

+8
-90
lines changed

doc/source/reference/extensions.rst

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ objects.
3434
3535
api.extensions.ExtensionArray._concat_same_type
3636
api.extensions.ExtensionArray._formatter
37-
api.extensions.ExtensionArray._formatting_values
3837
api.extensions.ExtensionArray._from_factorized
3938
api.extensions.ExtensionArray._from_sequence
4039
api.extensions.ExtensionArray._from_sequence_of_strings

doc/source/whatsnew/v1.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Removal of prior version deprecations/changes
6565
- Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to False (:issue:`27600`)
6666
- :meth:`pandas.Series.str.cat` now defaults to aligning ``others``, using ``join='left'`` (:issue:`27611`)
6767
- :meth:`pandas.Series.str.cat` does not accept list-likes *within* list-likes anymore (:issue:`27611`)
68-
-
68+
- Removed the previously deprecated :meth:`ExtensionArray._formatting_values`. Use :attr:`ExtensionArray._formatter` instead. (:issue:`23601`)
6969

7070
.. _whatsnew_1000.performance:
7171

pandas/core/arrays/base.py

-16
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ class ExtensionArray:
6666
unique
6767
_concat_same_type
6868
_formatter
69-
_formatting_values
7069
_from_factorized
7170
_from_sequence
7271
_from_sequence_of_strings
@@ -908,21 +907,6 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], Optional[str]]:
908907
return str
909908
return repr
910909

911-
def _formatting_values(self) -> np.ndarray:
912-
# At the moment, this has to be an array since we use result.dtype
913-
"""
914-
An array of values to be printed in, e.g. the Series repr
915-
916-
.. deprecated:: 0.24.0
917-
918-
Use :meth:`ExtensionArray._formatter` instead.
919-
920-
Returns
921-
-------
922-
array : ndarray
923-
"""
924-
return np.array(self)
925-
926910
# ------------------------------------------------------------------------
927911
# Reshaping
928912
# ------------------------------------------------------------------------

pandas/core/internals/blocks.py

+1-26
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,7 @@
6868
)
6969

7070
import pandas.core.algorithms as algos
71-
from pandas.core.arrays import (
72-
Categorical,
73-
DatetimeArray,
74-
ExtensionArray,
75-
PandasDtype,
76-
TimedeltaArray,
77-
)
71+
from pandas.core.arrays import Categorical, DatetimeArray, PandasDtype, TimedeltaArray
7872
from pandas.core.base import PandasObject
7973
import pandas.core.common as com
8074
from pandas.core.construction import extract_array
@@ -209,10 +203,6 @@ def internal_values(self, dtype=None):
209203
"""
210204
return self.values
211205

212-
def formatting_values(self):
213-
"""Return the internal values used by the DataFrame/SeriesFormatter"""
214-
return self.internal_values()
215-
216206
def get_values(self, dtype=None):
217207
"""
218208
return an internal format, currently just the ndarray
@@ -1831,21 +1821,6 @@ def _slice(self, slicer):
18311821

18321822
return self.values[slicer]
18331823

1834-
def formatting_values(self):
1835-
# Deprecating the ability to override _formatting_values.
1836-
# Do the warning here, it's only user in pandas, since we
1837-
# have to check if the subclass overrode it.
1838-
fv = getattr(type(self.values), "_formatting_values", None)
1839-
if fv and fv != ExtensionArray._formatting_values:
1840-
msg = (
1841-
"'ExtensionArray._formatting_values' is deprecated. "
1842-
"Specify 'ExtensionArray._formatter' instead."
1843-
)
1844-
warnings.warn(msg, FutureWarning, stacklevel=10)
1845-
return self.values._formatting_values()
1846-
1847-
return self.values
1848-
18491824
def concat_same_type(self, to_concat, placement=None):
18501825
"""
18511826
Concatenate list of single blocks of the same type.

pandas/core/internals/managers.py

-4
Original file line numberDiff line numberDiff line change
@@ -1582,10 +1582,6 @@ def external_values(self):
15821582
def internal_values(self):
15831583
return self._block.internal_values()
15841584

1585-
def formatting_values(self):
1586-
"""Return the internal values used by the DataFrame/SeriesFormatter"""
1587-
return self._block.formatting_values()
1588-
15891585
def get_values(self):
15901586
""" return a dense type view """
15911587
return np.array(self._block.to_dense(), copy=False)

pandas/core/series.py

-7
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,6 @@ def _values(self):
562562
"""
563563
return self._data.internal_values()
564564

565-
def _formatting_values(self):
566-
"""
567-
Return the values that can be formatted (used by SeriesFormatter
568-
and DataFrameFormatter).
569-
"""
570-
return self._data.formatting_values()
571-
572565
def get_values(self):
573566
"""
574567
Same as values (but handles sparseness conversions); is a view.

pandas/io/formats/format.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,11 @@ def _get_formatted_index(self) -> Tuple[List[str], bool]:
336336
return fmt_index, have_header
337337

338338
def _get_formatted_values(self) -> List[str]:
339-
values_to_format = self.tr_series._formatting_values()
340339
return format_array(
341-
values_to_format, None, float_format=self.float_format, na_rep=self.na_rep
340+
self.tr_series._values,
341+
None,
342+
float_format=self.float_format,
343+
na_rep=self.na_rep,
342344
)
343345

344346
def to_string(self) -> str:
@@ -903,9 +905,8 @@ def to_latex(
903905
def _format_col(self, i: int) -> List[str]:
904906
frame = self.tr_frame
905907
formatter = self._get_formatter(i)
906-
values_to_format = frame.iloc[:, i]._formatting_values()
907908
return format_array(
908-
values_to_format,
909+
frame.iloc[:, i]._values,
909910
formatter,
910911
float_format=self.float_format,
911912
na_rep=self.na_rep,

pandas/tests/extension/decimal/test_decimal.py

-11
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,6 @@ def test_ufunc_fallback(data):
392392
tm.assert_series_equal(result, expected)
393393

394394

395-
def test_formatting_values_deprecated():
396-
class DecimalArray2(DecimalArray):
397-
def _formatting_values(self):
398-
return np.array(self)
399-
400-
ser = pd.Series(DecimalArray2([decimal.Decimal("1.0")]))
401-
402-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
403-
repr(ser)
404-
405-
406395
def test_array_ufunc():
407396
a = to_decimal([1, 2, 3])
408397
result = np.exp(a)

pandas/tests/extension/test_external_block.py

+1-20
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
import pytest
33

44
import pandas as pd
5-
from pandas.core.internals import BlockManager, SingleBlockManager
5+
from pandas.core.internals import BlockManager
66
from pandas.core.internals.blocks import Block, NonConsolidatableMixIn
77

88

99
class CustomBlock(NonConsolidatableMixIn, Block):
1010

1111
_holder = np.ndarray
1212

13-
def formatting_values(self):
14-
return np.array(["Val: {}".format(i) for i in self.values])
15-
1613
def concat_same_type(self, to_concat, placement=None):
1714
"""
1815
Always concatenate disregarding self.ndim as the values are
@@ -35,22 +32,6 @@ def df():
3532
return pd.DataFrame(block_manager)
3633

3734

38-
def test_custom_repr():
39-
values = np.arange(3, dtype="int64")
40-
41-
# series
42-
block = CustomBlock(values, placement=slice(0, 3))
43-
44-
s = pd.Series(SingleBlockManager(block, pd.RangeIndex(3)))
45-
assert repr(s) == "0 Val: 0\n1 Val: 1\n2 Val: 2\ndtype: int64"
46-
47-
# dataframe
48-
block = CustomBlock(values, placement=slice(0, 1))
49-
blk_mgr = BlockManager([block], [["col"], range(3)])
50-
df = pd.DataFrame(blk_mgr)
51-
assert repr(df) == " col\n0 Val: 0\n1 Val: 1\n2 Val: 2"
52-
53-
5435
def test_concat_series():
5536
# GH17728
5637
values = np.arange(3, dtype="int64")

0 commit comments

Comments
 (0)