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

-21
This file was deleted.

pandas/_libs/tslibs/period.pyx

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

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

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

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

+4-13
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

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

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

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

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

pandas/core/panel.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,7 @@ def _compare_constructor(self, other, func):
344344

345345
def __unicode__(self):
346346
"""
347-
Return a string representation for a particular Panel.
348-
349-
Invoked by unicode(df) in py2 only.
350-
Yields a Unicode String in both py2/py3.
347+
Return a unicode string representation for a particular Panel.
351348
"""
352349

353350
class_name = str(self.__class__)

pandas/core/series.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1369,10 +1369,7 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False):
13691369

13701370
def __unicode__(self):
13711371
"""
1372-
Return a string representation for a particular DataFrame.
1373-
1374-
Invoked by unicode(df) in py2 only. Yields a Unicode String in both
1375-
py2/py3.
1372+
Return a unicode string representation for a particular DataFrame.
13761373
"""
13771374
buf = StringIO("")
13781375
width, height = get_terminal_size()

pandas/io/clipboard/clipboards.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ def copy_gtk(text):
3333

3434
def paste_gtk():
3535
clipboardContents = gtk.Clipboard().wait_for_text()
36-
# for python 2, returns None if the clipboard is blank.
37-
if clipboardContents is None:
38-
return ''
39-
else:
40-
return clipboardContents
36+
return clipboardContents
4137

4238
return copy_gtk, paste_gtk
4339

pandas/io/formats/printing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def pprint_thing(thing, _nest_lvl=0, escape_chars=None, default_escapes=False,
175175
176176
Returns
177177
-------
178-
result - unicode object on py2, str on py3. Always Unicode.
178+
result - unicode str
179179
180180
"""
181181

pandas/io/parsers.py

-6
Original file line numberDiff line numberDiff line change
@@ -1326,12 +1326,6 @@ def _validate_usecols_arg(usecols):
13261326

13271327
usecols = set(usecols)
13281328

1329-
if usecols_dtype == "unicode":
1330-
# see gh-13253
1331-
#
1332-
# Python 2.x compatibility
1333-
usecols = {col.encode("utf-8") for col in usecols}
1334-
13351329
return usecols, usecols_dtype
13361330
return usecols, None
13371331

pandas/tests/extension/json/array.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@
2727
class JSONDtype(ExtensionDtype):
2828
type = abc.Mapping
2929
name = 'json'
30-
31-
try:
32-
na_value = UserDict()
33-
except AttributeError:
34-
# source compatibility with Py2.
35-
na_value = {}
30+
na_value = UserDict()
3631

3732
@classmethod
3833
def construct_array_type(cls):

pandas/tests/extension/test_integer.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,7 @@ def _check_op(self, s, op, other, op_name, exc=NotImplementedError):
113113
result = op(s, other)
114114
expected = s.combine(other, op)
115115

116-
if op_name == '__rdiv__':
117-
# combine is not giving the correct result for this case
118-
pytest.skip("skipping reverse div in python 2")
119-
elif op_name in ('__rtruediv__', '__truediv__', '__div__'):
116+
if op_name in ('__rtruediv__', '__truediv__', '__div__'):
120117
expected = expected.astype(float)
121118
if op_name == '__rtruediv__':
122119
# TODO reverse operators result in object dtype

pandas/tests/indexes/test_base.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import math
77
import operator
88
import re
9-
import sys
109

1110
import numpy as np
1211
import pytest
@@ -414,9 +413,6 @@ def test_constructor_dtypes_datetime(self, tz_naive_fixture, attr, utc,
414413
index = index.tz_localize(tz_naive_fixture)
415414
dtype = index.dtype
416415

417-
# TODO(GH-24559): Remove the sys.modules and warnings
418-
# not sure what this is from. It's Py2 only.
419-
modules = [sys.modules['pandas.core.indexes.base']]
420416
if (tz_naive_fixture and attr == "asi8" and
421417
str(tz_naive_fixture) not in ('UTC', 'tzutc()', 'UTC+00:00')):
422418
ex_warn = FutureWarning
@@ -425,8 +421,7 @@ def test_constructor_dtypes_datetime(self, tz_naive_fixture, attr, utc,
425421

426422
# stacklevel is checked elsewhere. We don't do it here since
427423
# Index will have an frame, throwing off the expected.
428-
with tm.assert_produces_warning(ex_warn, check_stacklevel=False,
429-
clear=modules):
424+
with tm.assert_produces_warning(ex_warn, check_stacklevel=False):
430425
result = klass(arg, tz=tz_naive_fixture)
431426
tm.assert_index_equal(result, index)
432427

pandas/tests/io/formats/test_to_csv.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def test_to_csv_defualt_encoding(self):
4949
df = DataFrame({'col': ["AAAAA", "ÄÄÄÄÄ", "ßßßßß", "聞聞聞聞聞"]})
5050

5151
with tm.ensure_clean('test.csv') as path:
52-
# the default to_csv encoding in Python 2 is ascii, and that in
53-
# Python 3 is uft-8.
52+
# the default to_csv encoding is uft-8.
5453
df.to_csv(path)
5554
tm.assert_frame_equal(pd.read_csv(path, index_col=0), df)
5655

pandas/tests/io/parser/test_c_parser_only.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def test_read_nrows_large(c_parser_only):
416416

417417

418418
def test_float_precision_round_trip_with_text(c_parser_only):
419-
# see gh-15140 - This should not segfault on Python 2.7+
419+
# see gh-15140
420420
parser = c_parser_only
421421
df = parser.read_csv(StringIO("a"), header=None,
422422
float_precision="round_trip")

pandas/tests/io/test_compression.py

-5
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ def test_series_compression_defaults_to_infer(
100100
def test_compression_warning(compression_only):
101101
# Assert that passing a file object to to_csv while explicitly specifying a
102102
# compression protocol triggers a RuntimeWarning, as per GH21227.
103-
# Note that pytest has an issue that causes assert_produces_warning to fail
104-
# in Python 2 if the warning has occurred in previous tests
105-
# (see https://git.io/fNEBm & https://git.io/fNEBC). Hence, should this
106-
# test fail in just Python 2 builds, it likely indicates that other tests
107-
# are producing RuntimeWarnings, thereby triggering the pytest bug.
108103
df = pd.DataFrame(100 * [[0.123456, 0.234567, 0.567567],
109104
[12.32112, 123123.2, 321321.2]],
110105
columns=['X', 'Y', 'Z'])

pandas/tests/io/test_pickle.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,7 @@ def compare_element(result, expected, typ, version=None):
6565

6666
def compare(data, vf, version):
6767

68-
# py3 compat when reading py2 pickle
69-
try:
70-
data = pd.read_pickle(vf)
71-
except (ValueError) as e:
72-
if 'unsupported pickle protocol:' in str(e):
73-
# trying to read a py3 pickle in py2
74-
return
75-
else:
76-
raise
68+
data = pd.read_pickle(vf)
7769

7870
m = globals()
7971
for typ, dv in data.items():

scripts/merge-pr.py

-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import sys
3131
import textwrap
3232

33-
from six.moves import input
34-
3533
PANDAS_HOME = '.'
3634
PROJECT_NAME = 'pandas'
3735
print("PANDAS_HOME = " + PANDAS_HOME)

0 commit comments

Comments
 (0)