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

+2-2
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

+1-1
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

+5-8
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

+1-1
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

+5-5
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

+3-3
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

+1-1
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

+2-2
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

+2-2
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

+2-2
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):

pandas/core/indexes/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -933,9 +933,9 @@ def __deepcopy__(self, memo=None):
933933
# --------------------------------------------------------------------
934934
# Rendering Methods
935935

936-
def __unicode__(self):
936+
def __str__(self):
937937
"""
938-
Return a unicode string representation for this object.
938+
Return a string representation for this object.
939939
"""
940940
klass = self.__class__.__name__
941941
data = self._format_data()

pandas/core/indexes/frozen.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _disabled(self, *args, **kwargs):
108108
raise TypeError("'%s' does not support mutable operations." %
109109
self.__class__.__name__)
110110

111-
def __unicode__(self):
111+
def __str__(self):
112112
return pprint_thing(self, quote_strings=True,
113113
escape_chars=('\t', '\r', '\n'))
114114

@@ -149,9 +149,9 @@ def values(self):
149149
arr = self.view(np.ndarray).copy()
150150
return arr
151151

152-
def __unicode__(self):
152+
def __str__(self):
153153
"""
154-
Return a unicode string representation for this object.
154+
Return a string representation for this object.
155155
"""
156156
prepr = pprint_thing(self, escape_chars=('\t', '\r', '\n'),
157157
quote_strings=True)

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def make_block_same_class(self, values, placement=None, ndim=None,
232232
return make_block(values, placement=placement, ndim=ndim,
233233
klass=self.__class__, dtype=dtype)
234234

235-
def __unicode__(self):
235+
def __str__(self):
236236

237237
# don't want to print out all of the items here
238238
name = pprint_thing(self.__class__.__name__)

pandas/core/internals/managers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def _post_setstate(self):
291291
def __len__(self):
292292
return len(self.items)
293293

294-
def __unicode__(self):
294+
def __str__(self):
295295
output = pprint_thing(self.__class__.__name__)
296296
for i, ax in enumerate(self.axes):
297297
if i == 0:

pandas/core/panel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,9 @@ def _compare_constructor(self, other, func):
340340
# ----------------------------------------------------------------------
341341
# Magic methods
342342

343-
def __unicode__(self):
343+
def __str__(self):
344344
"""
345-
Return a unicode string representation for a particular Panel.
345+
Return a string representation for a particular Panel.
346346
"""
347347

348348
class_name = str(self.__class__)

pandas/core/resample.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(self, obj, groupby=None, axis=0, kind=None, **kwargs):
7979
if self.groupby is not None:
8080
self.groupby._set_grouper(self._convert_obj(obj), sort=True)
8181

82-
def __unicode__(self):
82+
def __str__(self):
8383
"""
8484
Provide a nice str repr of our rolling object.
8585
"""

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1387,9 +1387,9 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False):
13871387
# ----------------------------------------------------------------------
13881388
# Rendering Methods
13891389

1390-
def __unicode__(self):
1390+
def __str__(self):
13911391
"""
1392-
Return a unicode string representation for a particular DataFrame.
1392+
Return a string representation for a particular Series.
13931393
"""
13941394
buf = StringIO("")
13951395
width, height = get_terminal_size()

pandas/core/sparse/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ def as_sparse_array(self, kind=None, fill_value=None, copy=False):
217217
return SparseArray(self.values, sparse_index=self.sp_index,
218218
fill_value=fill_value, kind=kind, copy=copy)
219219

220-
def __unicode__(self):
220+
def __str__(self):
221221
# currently, unicode is same as repr...fixes infinite loop
222-
series_rep = Series.__unicode__(self)
222+
series_rep = Series.__str__(self)
223223
rep = '{series}\n{index!r}'.format(series=series_rep,
224224
index=self.sp_index)
225225
return rep

pandas/core/window.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def _get_window(self, other=None):
156156
def _window_type(self):
157157
return self.__class__.__name__
158158

159-
def __unicode__(self):
159+
def __str__(self):
160160
"""
161161
Provide a nice str repr of our rolling object.
162162
"""

pandas/io/pytables.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def __contains__(self, key):
519519
def __len__(self):
520520
return len(self.groups())
521521

522-
def __unicode__(self):
522+
def __str__(self):
523523
return '{type}\nFile path: {path}\n'.format(
524524
type=type(self), path=pprint_thing(self._path))
525525

@@ -1586,7 +1586,7 @@ def set_table(self, table):
15861586
self.table = table
15871587
return self
15881588

1589-
def __unicode__(self):
1589+
def __str__(self):
15901590
temp = tuple(
15911591
map(pprint_thing,
15921592
(self.name,
@@ -1880,7 +1880,7 @@ def __init__(self, values=None, kind=None, typ=None,
18801880
self.set_data(data)
18811881
self.set_metadata(metadata)
18821882

1883-
def __unicode__(self):
1883+
def __str__(self):
18841884
temp = tuple(
18851885
map(pprint_thing,
18861886
(self.name,
@@ -2335,7 +2335,7 @@ def pandas_type(self):
23352335
def format_type(self):
23362336
return 'fixed'
23372337

2338-
def __unicode__(self):
2338+
def __str__(self):
23392339
""" return a pretty representation of myself """
23402340
self.infer_axes()
23412341
s = self.shape
@@ -3076,7 +3076,7 @@ def table_type_short(self):
30763076
def format_type(self):
30773077
return 'table'
30783078

3079-
def __unicode__(self):
3079+
def __str__(self):
30803080
""" return a pretty representatgion of myself """
30813081
self.infer_axes()
30823082
dc = ",dc->[{columns}]".format(columns=(','.join(

pandas/io/stata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ def __init__(self, value):
804804
value = property(lambda self: self._value,
805805
doc='The binary representation of the missing value.')
806806

807-
def __unicode__(self):
807+
def __str__(self):
808808
return self.string
809809

810810
def __repr__(self):

pandas/tests/extension/decimal/test_decimal.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,6 @@ def _formatting_values(self):
387387

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

390-
with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=True):
390+
with tm.assert_produces_warning(DeprecationWarning,
391+
check_stacklevel=False):
391392
repr(ser)

pandas/tests/indexes/datetimes/test_formats.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_dti_repr_short(self):
6262
dr = pd.date_range(start='1/1/2012', periods=3)
6363
repr(dr)
6464

65-
@pytest.mark.parametrize('method', ['__repr__', '__unicode__', '__str__'])
65+
@pytest.mark.parametrize('method', ['__repr__', '__str__'])
6666
def test_dti_representation(self, method):
6767
idxs = []
6868
idxs.append(DatetimeIndex([], freq='D'))

pandas/tests/indexes/period/test_formats.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_frame_repr(self):
6161
'2000-01-03 3')
6262
assert result == expected
6363

64-
@pytest.mark.parametrize('method', ['__repr__', '__unicode__', '__str__'])
64+
@pytest.mark.parametrize('method', ['__repr__', '__str__'])
6565
def test_representation(self, method):
6666
# GH#7601
6767
idx1 = PeriodIndex([], freq='D')

pandas/tests/indexes/timedeltas/test_formats.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class TestTimedeltaIndexRendering:
8-
@pytest.mark.parametrize('method', ['__repr__', '__unicode__', '__str__'])
8+
@pytest.mark.parametrize('method', ['__repr__', '__str__'])
99
def test_representation(self, method):
1010
idx1 = TimedeltaIndex([], freq='D')
1111
idx2 = TimedeltaIndex(['1 days'], freq='D')

0 commit comments

Comments
 (0)