Skip to content

Commit 62c0ed0

Browse files
topper-123jreback
authored andcommitted
CLN: remove __unicode__ (#26432)
1 parent 2726a6a commit 62c0ed0

File tree

26 files changed

+53
-55
lines changed

26 files changed

+53
-55
lines changed

pandas/core/arrays/categorical.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,9 +2022,9 @@ def _get_repr(self, length=True, na_rep='NaN', footer=True):
20222022
result = formatter.to_string()
20232023
return str(result)
20242024

2025-
def __unicode__(self):
2025+
def __str__(self):
20262026
"""
2027-
Unicode representation.
2027+
String representation.
20282028
"""
20292029
_maxlen = 10
20302030
if len(self._codes) > _maxlen:

pandas/core/arrays/sparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ def _add_comparison_ops(cls):
18231823
# ----------
18241824
# Formatting
18251825
# -----------
1826-
def __unicode__(self):
1826+
def __str__(self):
18271827
return '{self}\nFill: {fill}\n{index}'.format(
18281828
self=printing.pprint_thing(self),
18291829
fill=printing.pprint_thing(self.fill_value),

pandas/core/base.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,28 @@
3434

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

4242
# ----------------------------------------------------------------------
4343
# Formatting
4444

45-
def __unicode__(self):
46-
raise AbstractMethodError(self)
47-
4845
def __str__(self):
4946
"""
5047
Return a string representation for a particular Object
5148
"""
52-
return self.__unicode__()
49+
raise AbstractMethodError(self)
5350

5451
def __bytes__(self):
5552
"""
56-
Return a string representation for a particular object.
53+
Return a bytes representation for a particular object.
5754
"""
5855
from pandas._config import get_option
5956

6057
encoding = get_option("display.encoding")
61-
return self.__unicode__().encode(encoding, 'replace')
58+
return str(self).encode(encoding, 'replace')
6259

6360
def __repr__(self):
6461
"""
@@ -76,7 +73,7 @@ def _constructor(self):
7673
"""class constructor (for this class it's just `__class__`"""
7774
return self.__class__
7875

79-
def __unicode__(self):
76+
def __str__(self):
8077
"""
8178
Return a string representation for a particular object.
8279
"""

pandas/core/computation/expr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ def assigner(self):
734734
def __call__(self):
735735
return self.terms(self.env)
736736

737-
def __unicode__(self):
737+
def __str__(self):
738738
return printing.pprint_thing(self.terms)
739739

740740
def __len__(self):

pandas/core/computation/ops.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self, name, env, side=None, encoding=None):
6767
def local_name(self):
6868
return self.name.replace(_LOCAL_TAG, '')
6969

70-
def __unicode__(self):
70+
def __str__(self):
7171
return pprint_thing(self.name)
7272

7373
def __call__(self, *args, **kwargs):
@@ -166,7 +166,7 @@ def _resolve_name(self):
166166
def name(self):
167167
return self.value
168168

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

191-
def __unicode__(self):
191+
def __str__(self):
192192
"""Print a generic n-ary operator and its operands using infix
193193
notation"""
194194
# recurse over the operands
@@ -506,7 +506,7 @@ def __call__(self, env):
506506
operand = self.operand(env)
507507
return self.func(operand)
508508

509-
def __unicode__(self):
509+
def __str__(self):
510510
return pprint_thing('{0}({1})'.format(self.op, self.operand))
511511

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

534-
def __unicode__(self):
534+
def __str__(self):
535535
operands = map(str, self.operands)
536536
return pprint_thing('{0}({1})'.format(self.op, ','.join(operands)))
537537

pandas/core/computation/pytables.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def convert_values(self):
230230

231231
class FilterBinOp(BinOp):
232232

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

@@ -302,7 +302,7 @@ def evaluate(self):
302302

303303
class ConditionBinOp(BinOp):
304304

305-
def __unicode__(self):
305+
def __str__(self):
306306
return pprint_thing("[Condition : [{cond}]]"
307307
.format(cond=self.condition))
308308

@@ -549,7 +549,7 @@ def __init__(self, where, queryables=None, encoding=None, scope_level=0):
549549
encoding=encoding)
550550
self.terms = self.parse()
551551

552-
def __unicode__(self):
552+
def __str__(self):
553553
if self.terms is not None:
554554
return pprint_thing(self.terms)
555555
return pprint_thing(self.expr)

pandas/core/computation/scope.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def __init__(self, level, global_dict=None, local_dict=None, resolvers=(),
135135
self.resolvers = DeepChainMap(*resolvers)
136136
self.temps = {}
137137

138-
def __unicode__(self):
138+
def __str__(self):
139139
scope_keys = _get_pretty_string(list(self.scope.keys()))
140140
res_keys = _get_pretty_string(list(self.resolvers.keys()))
141141
unicode_str = '{name}(scope={scope_keys}, resolvers={res_keys})'

pandas/core/frame.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,9 @@ def _info_repr(self):
610610
return info_repr_option and not (self._repr_fits_horizontal_() and
611611
self._repr_fits_vertical_())
612612

613-
def __unicode__(self):
613+
def __str__(self):
614614
"""
615-
Return a unicode string representation for a particular DataFrame.
615+
Return a string representation for a particular DataFrame.
616616
"""
617617
buf = StringIO("")
618618
if self._info_repr():

pandas/core/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,8 +2022,8 @@ def __setstate__(self, state):
20222022
# ----------------------------------------------------------------------
20232023
# Rendering Methods
20242024

2025-
def __unicode__(self):
2026-
# unicode representation based upon iterating over self
2025+
def __str__(self):
2026+
# string representation based upon iterating over self
20272027
# (since, by definition, `PandasContainers` are iterable)
20282028
prepr = '[%s]' % ','.join(map(pprint_thing, self))
20292029
return '%s(%s)' % (self.__class__.__name__, prepr)

pandas/core/groupby/groupby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,8 @@ def __init__(self, obj, keys=None, axis=0, level=None,
373373
def __len__(self):
374374
return len(self.groups)
375375

376-
def __unicode__(self):
377-
# TODO: Better unicode/repr for GroupBy object
376+
def __str__(self):
377+
# TODO: Better str/repr for GroupBy object
378378
return object.__repr__(self)
379379

380380
def _assure_grouper(self):

0 commit comments

Comments
 (0)