Skip to content

CLN: remove __unicode__ from code base #26432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2022,9 +2022,9 @@ def _get_repr(self, length=True, na_rep='NaN', footer=True):
result = formatter.to_string()
return str(result)

def __unicode__(self):
def __str__(self):
"""
Unicode representation.
String representation.
"""
_maxlen = 10
if len(self._codes) > _maxlen:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ def _add_comparison_ops(cls):
# ----------
# Formatting
# -----------
def __unicode__(self):
def __str__(self):
return '{self}\nFill: {fill}\n{index}'.format(
self=printing.pprint_thing(self),
fill=printing.pprint_thing(self.fill_value),
Expand Down
13 changes: 5 additions & 8 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,28 @@

class StringMixin:
"""
Implements string methods so long as object defines a `__unicode__` method.
Implements string methods so long as object defines a `__str__` method.
"""
# side note - this could be made into a metaclass if more than one
# object needs

# ----------------------------------------------------------------------
# Formatting

def __unicode__(self):
raise AbstractMethodError(self)

def __str__(self):
"""
Return a string representation for a particular Object
"""
return self.__unicode__()
raise AbstractMethodError(self)

def __bytes__(self):
"""
Return a string representation for a particular object.
Return a bytes representation for a particular object.
"""
from pandas._config import get_option

encoding = get_option("display.encoding")
return self.__unicode__().encode(encoding, 'replace')
return str(self).encode(encoding, 'replace')

def __repr__(self):
"""
Expand All @@ -76,7 +73,7 @@ def _constructor(self):
"""class constructor (for this class it's just `__class__`"""
return self.__class__

def __unicode__(self):
def __str__(self):
"""
Return a string representation for a particular object.
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ def assigner(self):
def __call__(self):
return self.terms(self.env)

def __unicode__(self):
def __str__(self):
return printing.pprint_thing(self.terms)

def __len__(self):
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, name, env, side=None, encoding=None):
def local_name(self):
return self.name.replace(_LOCAL_TAG, '')

def __unicode__(self):
def __str__(self):
return pprint_thing(self.name)

def __call__(self, *args, **kwargs):
Expand Down Expand Up @@ -166,7 +166,7 @@ def _resolve_name(self):
def name(self):
return self.value

def __unicode__(self):
def __str__(self):
# in python 2 str() of float
# can truncate shorter than repr()
return repr(self.name)
Expand All @@ -188,7 +188,7 @@ def __init__(self, op, operands, *args, **kwargs):
def __iter__(self):
return iter(self.operands)

def __unicode__(self):
def __str__(self):
"""Print a generic n-ary operator and its operands using infix
notation"""
# recurse over the operands
Expand Down Expand Up @@ -506,7 +506,7 @@ def __call__(self, env):
operand = self.operand(env)
return self.func(operand)

def __unicode__(self):
def __str__(self):
return pprint_thing('{0}({1})'.format(self.op, self.operand))

@property
Expand All @@ -531,7 +531,7 @@ def __call__(self, env):
with np.errstate(all='ignore'):
return self.func.func(*operands)

def __unicode__(self):
def __str__(self):
operands = map(str, self.operands)
return pprint_thing('{0}({1})'.format(self.op, ','.join(operands)))

Expand Down
6 changes: 3 additions & 3 deletions pandas/core/computation/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def convert_values(self):

class FilterBinOp(BinOp):

def __unicode__(self):
def __str__(self):
return pprint_thing("[Filter : [{lhs}] -> [{op}]"
.format(lhs=self.filter[0], op=self.filter[1]))

Expand Down Expand Up @@ -302,7 +302,7 @@ def evaluate(self):

class ConditionBinOp(BinOp):

def __unicode__(self):
def __str__(self):
return pprint_thing("[Condition : [{cond}]]"
.format(cond=self.condition))

Expand Down Expand Up @@ -549,7 +549,7 @@ def __init__(self, where, queryables=None, encoding=None, scope_level=0):
encoding=encoding)
self.terms = self.parse()

def __unicode__(self):
def __str__(self):
if self.terms is not None:
return pprint_thing(self.terms)
return pprint_thing(self.expr)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(self, level, global_dict=None, local_dict=None, resolvers=(),
self.resolvers = DeepChainMap(*resolvers)
self.temps = {}

def __unicode__(self):
def __str__(self):
scope_keys = _get_pretty_string(list(self.scope.keys()))
res_keys = _get_pretty_string(list(self.resolvers.keys()))
unicode_str = '{name}(scope={scope_keys}, resolvers={res_keys})'
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ def _info_repr(self):
return info_repr_option and not (self._repr_fits_horizontal_() and
self._repr_fits_vertical_())

def __unicode__(self):
def __str__(self):
"""
Return a unicode string representation for a particular DataFrame.
Return a string representation for a particular DataFrame.
"""
buf = StringIO("")
if self._info_repr():
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2022,8 +2022,8 @@ def __setstate__(self, state):
# ----------------------------------------------------------------------
# Rendering Methods

def __unicode__(self):
# unicode representation based upon iterating over self
def __str__(self):
# string representation based upon iterating over self
# (since, by definition, `PandasContainers` are iterable)
prepr = '[%s]' % ','.join(map(pprint_thing, self))
return '%s(%s)' % (self.__class__.__name__, prepr)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ def __init__(self, obj, keys=None, axis=0, level=None,
def __len__(self):
return len(self.groups)

def __unicode__(self):
# TODO: Better unicode/repr for GroupBy object
def __str__(self):
# TODO: Better str/repr for GroupBy object
return object.__repr__(self)

def _assure_grouper(self):
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,9 +933,9 @@ def __deepcopy__(self, memo=None):
# --------------------------------------------------------------------
# Rendering Methods

def __unicode__(self):
def __str__(self):
"""
Return a unicode string representation for this object.
Return a string representation for this object.
"""
klass = self.__class__.__name__
data = self._format_data()
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/indexes/frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _disabled(self, *args, **kwargs):
raise TypeError("'%s' does not support mutable operations." %
self.__class__.__name__)

def __unicode__(self):
def __str__(self):
return pprint_thing(self, quote_strings=True,
escape_chars=('\t', '\r', '\n'))

Expand Down Expand Up @@ -149,9 +149,9 @@ def values(self):
arr = self.view(np.ndarray).copy()
return arr

def __unicode__(self):
def __str__(self):
"""
Return a unicode string representation for this object.
Return a string representation for this object.
"""
prepr = pprint_thing(self, escape_chars=('\t', '\r', '\n'),
quote_strings=True)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def make_block_same_class(self, values, placement=None, ndim=None,
return make_block(values, placement=placement, ndim=ndim,
klass=self.__class__, dtype=dtype)

def __unicode__(self):
def __str__(self):

# don't want to print out all of the items here
name = pprint_thing(self.__class__.__name__)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _post_setstate(self):
def __len__(self):
return len(self.items)

def __unicode__(self):
def __str__(self):
output = pprint_thing(self.__class__.__name__)
for i, ax in enumerate(self.axes):
if i == 0:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,9 @@ def _compare_constructor(self, other, func):
# ----------------------------------------------------------------------
# Magic methods

def __unicode__(self):
def __str__(self):
"""
Return a unicode string representation for a particular Panel.
Return a string representation for a particular Panel.
"""

class_name = str(self.__class__)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, obj, groupby=None, axis=0, kind=None, **kwargs):
if self.groupby is not None:
self.groupby._set_grouper(self._convert_obj(obj), sort=True)

def __unicode__(self):
def __str__(self):
"""
Provide a nice str repr of our rolling object.
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,9 +1387,9 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False):
# ----------------------------------------------------------------------
# Rendering Methods

def __unicode__(self):
def __str__(self):
"""
Return a unicode string representation for a particular DataFrame.
Return a string representation for a particular Series.
"""
buf = StringIO("")
width, height = get_terminal_size()
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/sparse/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ def as_sparse_array(self, kind=None, fill_value=None, copy=False):
return SparseArray(self.values, sparse_index=self.sp_index,
fill_value=fill_value, kind=kind, copy=copy)

def __unicode__(self):
def __str__(self):
# currently, unicode is same as repr...fixes infinite loop
series_rep = Series.__unicode__(self)
series_rep = Series.__str__(self)
rep = '{series}\n{index!r}'.format(series=series_rep,
index=self.sp_index)
return rep
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _get_window(self, other=None):
def _window_type(self):
return self.__class__.__name__

def __unicode__(self):
def __str__(self):
"""
Provide a nice str repr of our rolling object.
"""
Expand Down
10 changes: 5 additions & 5 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def __contains__(self, key):
def __len__(self):
return len(self.groups())

def __unicode__(self):
def __str__(self):
return '{type}\nFile path: {path}\n'.format(
type=type(self), path=pprint_thing(self._path))

Expand Down Expand Up @@ -1586,7 +1586,7 @@ def set_table(self, table):
self.table = table
return self

def __unicode__(self):
def __str__(self):
temp = tuple(
map(pprint_thing,
(self.name,
Expand Down Expand Up @@ -1880,7 +1880,7 @@ def __init__(self, values=None, kind=None, typ=None,
self.set_data(data)
self.set_metadata(metadata)

def __unicode__(self):
def __str__(self):
temp = tuple(
map(pprint_thing,
(self.name,
Expand Down Expand Up @@ -2335,7 +2335,7 @@ def pandas_type(self):
def format_type(self):
return 'fixed'

def __unicode__(self):
def __str__(self):
""" return a pretty representation of myself """
self.infer_axes()
s = self.shape
Expand Down Expand Up @@ -3076,7 +3076,7 @@ def table_type_short(self):
def format_type(self):
return 'table'

def __unicode__(self):
def __str__(self):
""" return a pretty representatgion of myself """
self.infer_axes()
dc = ",dc->[{columns}]".format(columns=(','.join(
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ def __init__(self, value):
value = property(lambda self: self._value,
doc='The binary representation of the missing value.')

def __unicode__(self):
def __str__(self):
return self.string

def __repr__(self):
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/extension/decimal/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,5 +387,6 @@ def _formatting_values(self):

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

with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=True):
with tm.assert_produces_warning(DeprecationWarning,
check_stacklevel=False):
repr(ser)
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_dti_repr_short(self):
dr = pd.date_range(start='1/1/2012', periods=3)
repr(dr)

@pytest.mark.parametrize('method', ['__repr__', '__unicode__', '__str__'])
@pytest.mark.parametrize('method', ['__repr__', '__str__'])
def test_dti_representation(self, method):
idxs = []
idxs.append(DatetimeIndex([], freq='D'))
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/period/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_frame_repr(self):
'2000-01-03 3')
assert result == expected

@pytest.mark.parametrize('method', ['__repr__', '__unicode__', '__str__'])
@pytest.mark.parametrize('method', ['__repr__', '__str__'])
def test_representation(self, method):
# GH#7601
idx1 = PeriodIndex([], freq='D')
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/timedeltas/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class TestTimedeltaIndexRendering:
@pytest.mark.parametrize('method', ['__repr__', '__unicode__', '__str__'])
@pytest.mark.parametrize('method', ['__repr__', '__str__'])
def test_representation(self, method):
idx1 = TimedeltaIndex([], freq='D')
idx2 = TimedeltaIndex(['1 days'], freq='D')
Expand Down
Loading