Skip to content

Commit

Permalink
DEPR: Removed the previously deprecated ExtensionArray._formatting_va…
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjayhawkins authored and jorisvandenbossche committed Aug 7, 2019
1 parent 54e5803 commit a45760f
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 90 deletions.
1 change: 0 additions & 1 deletion doc/source/reference/extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ objects.
api.extensions.ExtensionArray._concat_same_type
api.extensions.ExtensionArray._formatter
api.extensions.ExtensionArray._formatting_values
api.extensions.ExtensionArray._from_factorized
api.extensions.ExtensionArray._from_sequence
api.extensions.ExtensionArray._from_sequence_of_strings
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Removal of prior version deprecations/changes
- Changed the the default value of `inplace` in :meth:`DataFrame.set_index` and :meth:`Series.set_axis`. It now defaults to False (:issue:`27600`)
- :meth:`pandas.Series.str.cat` now defaults to aligning ``others``, using ``join='left'`` (:issue:`27611`)
- :meth:`pandas.Series.str.cat` does not accept list-likes *within* list-likes anymore (:issue:`27611`)
-
- Removed the previously deprecated :meth:`ExtensionArray._formatting_values`. Use :attr:`ExtensionArray._formatter` instead. (:issue:`23601`)

.. _whatsnew_1000.performance:

Expand Down
16 changes: 0 additions & 16 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class ExtensionArray:
unique
_concat_same_type
_formatter
_formatting_values
_from_factorized
_from_sequence
_from_sequence_of_strings
Expand Down Expand Up @@ -908,21 +907,6 @@ def _formatter(self, boxed: bool = False) -> Callable[[Any], Optional[str]]:
return str
return repr

def _formatting_values(self) -> np.ndarray:
# At the moment, this has to be an array since we use result.dtype
"""
An array of values to be printed in, e.g. the Series repr
.. deprecated:: 0.24.0
Use :meth:`ExtensionArray._formatter` instead.
Returns
-------
array : ndarray
"""
return np.array(self)

# ------------------------------------------------------------------------
# Reshaping
# ------------------------------------------------------------------------
Expand Down
27 changes: 1 addition & 26 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@
)

import pandas.core.algorithms as algos
from pandas.core.arrays import (
Categorical,
DatetimeArray,
ExtensionArray,
PandasDtype,
TimedeltaArray,
)
from pandas.core.arrays import Categorical, DatetimeArray, PandasDtype, TimedeltaArray
from pandas.core.base import PandasObject
import pandas.core.common as com
from pandas.core.construction import extract_array
Expand Down Expand Up @@ -209,10 +203,6 @@ def internal_values(self, dtype=None):
"""
return self.values

def formatting_values(self):
"""Return the internal values used by the DataFrame/SeriesFormatter"""
return self.internal_values()

def get_values(self, dtype=None):
"""
return an internal format, currently just the ndarray
Expand Down Expand Up @@ -1831,21 +1821,6 @@ def _slice(self, slicer):

return self.values[slicer]

def formatting_values(self):
# Deprecating the ability to override _formatting_values.
# Do the warning here, it's only user in pandas, since we
# have to check if the subclass overrode it.
fv = getattr(type(self.values), "_formatting_values", None)
if fv and fv != ExtensionArray._formatting_values:
msg = (
"'ExtensionArray._formatting_values' is deprecated. "
"Specify 'ExtensionArray._formatter' instead."
)
warnings.warn(msg, FutureWarning, stacklevel=10)
return self.values._formatting_values()

return self.values

def concat_same_type(self, to_concat, placement=None):
"""
Concatenate list of single blocks of the same type.
Expand Down
4 changes: 0 additions & 4 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1582,10 +1582,6 @@ def external_values(self):
def internal_values(self):
return self._block.internal_values()

def formatting_values(self):
"""Return the internal values used by the DataFrame/SeriesFormatter"""
return self._block.formatting_values()

def get_values(self):
""" return a dense type view """
return np.array(self._block.to_dense(), copy=False)
Expand Down
7 changes: 0 additions & 7 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,6 @@ def _values(self):
"""
return self._data.internal_values()

def _formatting_values(self):
"""
Return the values that can be formatted (used by SeriesFormatter
and DataFrameFormatter).
"""
return self._data.formatting_values()

def get_values(self):
"""
Same as values (but handles sparseness conversions); is a view.
Expand Down
9 changes: 5 additions & 4 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,11 @@ def _get_formatted_index(self) -> Tuple[List[str], bool]:
return fmt_index, have_header

def _get_formatted_values(self) -> List[str]:
values_to_format = self.tr_series._formatting_values()
return format_array(
values_to_format, None, float_format=self.float_format, na_rep=self.na_rep
self.tr_series._values,
None,
float_format=self.float_format,
na_rep=self.na_rep,
)

def to_string(self) -> str:
Expand Down Expand Up @@ -903,9 +905,8 @@ def to_latex(
def _format_col(self, i: int) -> List[str]:
frame = self.tr_frame
formatter = self._get_formatter(i)
values_to_format = frame.iloc[:, i]._formatting_values()
return format_array(
values_to_format,
frame.iloc[:, i]._values,
formatter,
float_format=self.float_format,
na_rep=self.na_rep,
Expand Down
11 changes: 0 additions & 11 deletions pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,6 @@ def test_ufunc_fallback(data):
tm.assert_series_equal(result, expected)


def test_formatting_values_deprecated():
class DecimalArray2(DecimalArray):
def _formatting_values(self):
return np.array(self)

ser = pd.Series(DecimalArray2([decimal.Decimal("1.0")]))

with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
repr(ser)


def test_array_ufunc():
a = to_decimal([1, 2, 3])
result = np.exp(a)
Expand Down
21 changes: 1 addition & 20 deletions pandas/tests/extension/test_external_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
import pytest

import pandas as pd
from pandas.core.internals import BlockManager, SingleBlockManager
from pandas.core.internals import BlockManager
from pandas.core.internals.blocks import Block, NonConsolidatableMixIn


class CustomBlock(NonConsolidatableMixIn, Block):

_holder = np.ndarray

def formatting_values(self):
return np.array(["Val: {}".format(i) for i in self.values])

def concat_same_type(self, to_concat, placement=None):
"""
Always concatenate disregarding self.ndim as the values are
Expand All @@ -35,22 +32,6 @@ def df():
return pd.DataFrame(block_manager)


def test_custom_repr():
values = np.arange(3, dtype="int64")

# series
block = CustomBlock(values, placement=slice(0, 3))

s = pd.Series(SingleBlockManager(block, pd.RangeIndex(3)))
assert repr(s) == "0 Val: 0\n1 Val: 1\n2 Val: 2\ndtype: int64"

# dataframe
block = CustomBlock(values, placement=slice(0, 1))
blk_mgr = BlockManager([block], [["col"], range(3)])
df = pd.DataFrame(blk_mgr)
assert repr(df) == " col\n0 Val: 0\n1 Val: 1\n2 Val: 2"


def test_concat_series():
# GH17728
values = np.arange(3, dtype="int64")
Expand Down

0 comments on commit a45760f

Please sign in to comment.