Skip to content

Commit 81f5c01

Browse files
mroeschkejreback
authored andcommitted
CLN: Misc Python 2 references (#26085)
1 parent d9c9e2f commit 81f5c01

File tree

23 files changed

+24
-129
lines changed

23 files changed

+24
-129
lines changed

LICENSES/SIX

Lines changed: 0 additions & 21 deletions
This file was deleted.

pandas/_libs/tslibs/period.pyx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,10 +2224,7 @@ cdef class _Period(object):
22242224

22252225
def __unicode__(self):
22262226
"""
2227-
Return a string representation for a particular DataFrame
2228-
2229-
Invoked by unicode(df) in py2 only. Yields a Unicode String in both
2230-
py2/py3.
2227+
Return a unicode string representation for a particular DataFrame
22312228
"""
22322229
base, mult = get_freq_code(self.freq)
22332230
formatted = period_format(self.ordinal, base)

pandas/_libs/tslibs/strptime.pyx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,7 @@ import calendar
77
import re
88
from datetime import date as datetime_date
99

10-
11-
# Python 2 vs Python 3
12-
try:
13-
from thread import allocate_lock as _thread_allocate_lock
14-
except:
15-
try:
16-
from _thread import allocate_lock as _thread_allocate_lock
17-
except:
18-
try:
19-
from dummy_thread import allocate_lock as _thread_allocate_lock
20-
except:
21-
from _dummy_thread import allocate_lock as _thread_allocate_lock
22-
10+
from _thread import allocate_lock as _thread_allocate_lock
2311

2412
import pytz
2513

pandas/core/base.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -699,12 +699,7 @@ def item(self):
699699
"""
700700
Return the first element of the underlying data as a python scalar.
701701
"""
702-
try:
703-
return self.values.item()
704-
except IndexError:
705-
# copy numpy's message here because Py26 raises an IndexError
706-
raise ValueError('can only convert an array of size 1 to a '
707-
'Python scalar')
702+
return self.values.item()
708703

709704
@property
710705
def data(self):

pandas/core/dtypes/cast.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,6 @@ def astype_nansafe(arr, dtype, copy=True, skipna=False):
636636
dtype = pandas_dtype(dtype)
637637

638638
if issubclass(dtype.type, str):
639-
# in Py3 that's str, in Py2 that's unicode
640639
return lib.astype_unicode(arr.ravel(),
641640
skipna=skipna).reshape(arr.shape)
642641

pandas/core/frame.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,7 @@ def _info_repr(self):
612612

613613
def __unicode__(self):
614614
"""
615-
Return a string representation for a particular DataFrame.
616-
617-
Invoked by unicode(df) in py2 only. Yields a Unicode String in both
618-
py2/py3.
615+
Return a unicode string representation for a particular DataFrame.
619616
"""
620617
buf = StringIO("")
621618
if self._info_repr():
@@ -901,16 +898,10 @@ def itertuples(self, index=True, name="Pandas"):
901898
# use integer indexing because of possible duplicate column names
902899
arrays.extend(self.iloc[:, k] for k in range(len(self.columns)))
903900

904-
# Python 3 supports at most 255 arguments to constructor, and
905-
# things get slow with this many fields in Python 2
901+
# Python 3 supports at most 255 arguments to constructor
906902
if name is not None and len(self.columns) + index < 256:
907-
# `rename` is unsupported in Python 2.6
908-
try:
909-
itertuple = collections.namedtuple(name, fields, rename=True)
910-
return map(itertuple._make, zip(*arrays))
911-
912-
except Exception:
913-
pass
903+
itertuple = collections.namedtuple(name, fields, rename=True)
904+
return map(itertuple._make, zip(*arrays))
914905

915906
# fallback to regular tuples
916907
return zip(*arrays)

pandas/core/generic.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,11 +2579,8 @@ def to_pickle(self, path, compression='infer',
25792579
protocol : int
25802580
Int which indicates which protocol should be used by the pickler,
25812581
default HIGHEST_PROTOCOL (see [1]_ paragraph 12.1.2). The possible
2582-
values for this parameter depend on the version of Python. For
2583-
Python 2.x, possible values are 0, 1, 2. For Python>=3.0, 3 is a
2584-
valid value. For Python >= 3.4, 4 is a valid value. A negative
2585-
value for the protocol parameter is equivalent to setting its value
2586-
to HIGHEST_PROTOCOL.
2582+
values are 0, 1, 2, 3, 4. A negative value for the protocol
2583+
parameter is equivalent to setting its value to HIGHEST_PROTOCOL.
25872584
25882585
.. [1] https://docs.python.org/3/library/pickle.html
25892586
.. versionadded:: 0.21.0
@@ -2836,7 +2833,7 @@ def to_latex(self, buf=None, columns=None, col_space=None, header=True,
28362833
characters in column names.
28372834
encoding : str, optional
28382835
A string representing the encoding to use in the output file,
2839-
defaults to 'ascii' on Python 2 and 'utf-8' on Python 3.
2836+
defaults to 'utf-8'.
28402837
decimal : str, default '.'
28412838
Character recognized as decimal separator, e.g. ',' in Europe.
28422839
@@ -2965,7 +2962,7 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
29652962
Python write mode, default 'w'.
29662963
encoding : str, optional
29672964
A string representing the encoding to use in the output file,
2968-
defaults to 'ascii' on Python 2 and 'utf-8' on Python 3.
2965+
defaults to 'utf-8'.
29692966
compression : str, default 'infer'
29702967
Compression mode among the following possible values: {'infer',
29712968
'gzip', 'bz2', 'zip', 'xz', None}. If 'infer' and `path_or_buf`

pandas/core/indexes/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -920,10 +920,7 @@ def __deepcopy__(self, memo=None):
920920

921921
def __unicode__(self):
922922
"""
923-
Return a string representation for this object.
924-
925-
Invoked by unicode(df) in py2 only. Yields a Unicode String in both
926-
py2/py3.
923+
Return a unicode string representation for this object.
927924
"""
928925
klass = self.__class__.__name__
929926
data = self._format_data()

pandas/core/indexes/frozen.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,7 @@ def values(self):
151151

152152
def __unicode__(self):
153153
"""
154-
Return a string representation for this object.
155-
156-
Invoked by unicode(df) in py2 only. Yields a Unicode String in both
157-
py2/py3.
154+
Return a unicode string representation for this object.
158155
"""
159156
prepr = pprint_thing(self, escape_chars=('\t', '\r', '\n'),
160157
quote_strings=True)

pandas/core/indexes/range.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def ensure_int(value, field):
126126

127127
@classmethod
128128
def from_range(cls, data, name=None, dtype=None, **kwargs):
129-
""" Create RangeIndex from a range (py3), or xrange (py2) object. """
129+
""" Create RangeIndex from a range object. """
130130
if not isinstance(data, range):
131131
raise TypeError(
132132
'{0}(...) must be called with object coercible to a '

0 commit comments

Comments
 (0)