diff --git a/LICENSES/SIX b/LICENSES/SIX deleted file mode 100644 index 6fd669af222d3..0000000000000 --- a/LICENSES/SIX +++ /dev/null @@ -1,21 +0,0 @@ -six license (substantial portions used in the python 3 compatibility module) -=========================================================================== -Copyright (c) 2010-2013 Benjamin Peterson - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: -# -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -# -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index e5b50ae3c19de..624cad2bfa95a 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -2224,10 +2224,7 @@ cdef class _Period(object): def __unicode__(self): """ - Return a string representation for a particular DataFrame - - Invoked by unicode(df) in py2 only. Yields a Unicode String in both - py2/py3. + Return a unicode string representation for a particular DataFrame """ base, mult = get_freq_code(self.freq) formatted = period_format(self.ordinal, base) diff --git a/pandas/_libs/tslibs/strptime.pyx b/pandas/_libs/tslibs/strptime.pyx index ff9e92aa05bb6..ddd5d0d224264 100644 --- a/pandas/_libs/tslibs/strptime.pyx +++ b/pandas/_libs/tslibs/strptime.pyx @@ -7,19 +7,7 @@ import calendar import re from datetime import date as datetime_date - -# Python 2 vs Python 3 -try: - from thread import allocate_lock as _thread_allocate_lock -except: - try: - from _thread import allocate_lock as _thread_allocate_lock - except: - try: - from dummy_thread import allocate_lock as _thread_allocate_lock - except: - from _dummy_thread import allocate_lock as _thread_allocate_lock - +from _thread import allocate_lock as _thread_allocate_lock import pytz diff --git a/pandas/core/base.py b/pandas/core/base.py index d4294e59cc845..6842a632223ed 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -699,12 +699,7 @@ def item(self): """ Return the first element of the underlying data as a python scalar. """ - try: - return self.values.item() - except IndexError: - # copy numpy's message here because Py26 raises an IndexError - raise ValueError('can only convert an array of size 1 to a ' - 'Python scalar') + return self.values.item() @property def data(self): diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 78754b13e1705..a2509226bcd8e 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -636,7 +636,6 @@ def astype_nansafe(arr, dtype, copy=True, skipna=False): dtype = pandas_dtype(dtype) if issubclass(dtype.type, str): - # in Py3 that's str, in Py2 that's unicode return lib.astype_unicode(arr.ravel(), skipna=skipna).reshape(arr.shape) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index fdc99e957e257..98b0555d3d771 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -615,10 +615,7 @@ def _info_repr(self): def __unicode__(self): """ - Return a string representation for a particular DataFrame. - - Invoked by unicode(df) in py2 only. Yields a Unicode String in both - py2/py3. + Return a unicode string representation for a particular DataFrame. """ buf = StringIO("") if self._info_repr(): @@ -904,16 +901,10 @@ def itertuples(self, index=True, name="Pandas"): # use integer indexing because of possible duplicate column names arrays.extend(self.iloc[:, k] for k in range(len(self.columns))) - # Python 3 supports at most 255 arguments to constructor, and - # things get slow with this many fields in Python 2 + # Python 3 supports at most 255 arguments to constructor if name is not None and len(self.columns) + index < 256: - # `rename` is unsupported in Python 2.6 - try: - itertuple = collections.namedtuple(name, fields, rename=True) - return map(itertuple._make, zip(*arrays)) - - except Exception: - pass + itertuple = collections.namedtuple(name, fields, rename=True) + return map(itertuple._make, zip(*arrays)) # fallback to regular tuples return zip(*arrays) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 885c499c58dfa..f785988d558da 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2581,11 +2581,8 @@ def to_pickle(self, path, compression='infer', protocol : int Int which indicates which protocol should be used by the pickler, default HIGHEST_PROTOCOL (see [1]_ paragraph 12.1.2). The possible - values for this parameter depend on the version of Python. For - Python 2.x, possible values are 0, 1, 2. For Python>=3.0, 3 is a - valid value. For Python >= 3.4, 4 is a valid value. A negative - value for the protocol parameter is equivalent to setting its value - to HIGHEST_PROTOCOL. + values are 0, 1, 2, 3, 4. A negative value for the protocol + parameter is equivalent to setting its value to HIGHEST_PROTOCOL. .. [1] https://docs.python.org/3/library/pickle.html .. versionadded:: 0.21.0 @@ -2838,7 +2835,7 @@ def to_latex(self, buf=None, columns=None, col_space=None, header=True, characters in column names. encoding : str, optional A string representing the encoding to use in the output file, - defaults to 'ascii' on Python 2 and 'utf-8' on Python 3. + defaults to 'utf-8'. decimal : str, default '.' Character recognized as decimal separator, e.g. ',' in Europe. @@ -2967,7 +2964,7 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None, Python write mode, default 'w'. encoding : str, optional A string representing the encoding to use in the output file, - defaults to 'ascii' on Python 2 and 'utf-8' on Python 3. + defaults to 'utf-8'. compression : str, default 'infer' Compression mode among the following possible values: {'infer', 'gzip', 'bz2', 'zip', 'xz', None}. If 'infer' and `path_or_buf` diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 98647a6895574..b89dc4c769c26 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -921,10 +921,7 @@ def __deepcopy__(self, memo=None): def __unicode__(self): """ - Return a string representation for this object. - - Invoked by unicode(df) in py2 only. Yields a Unicode String in both - py2/py3. + Return a unicode string representation for this object. """ klass = self.__class__.__name__ data = self._format_data() diff --git a/pandas/core/indexes/frozen.py b/pandas/core/indexes/frozen.py index 982645ebd5124..cad094e59b022 100644 --- a/pandas/core/indexes/frozen.py +++ b/pandas/core/indexes/frozen.py @@ -151,10 +151,7 @@ def values(self): def __unicode__(self): """ - Return a string representation for this object. - - Invoked by unicode(df) in py2 only. Yields a Unicode String in both - py2/py3. + Return a unicode string representation for this object. """ prepr = pprint_thing(self, escape_chars=('\t', '\r', '\n'), quote_strings=True) diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index da6a917c93ba4..5832d106dae34 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -126,7 +126,7 @@ def ensure_int(value, field): @classmethod def from_range(cls, data, name=None, dtype=None, **kwargs): - """ Create RangeIndex from a range (py3), or xrange (py2) object. """ + """ Create RangeIndex from a range object. """ if not isinstance(data, range): raise TypeError( '{0}(...) must be called with object coercible to a ' diff --git a/pandas/core/panel.py b/pandas/core/panel.py index 542b1075313bf..4181f6c8ca3ab 100644 --- a/pandas/core/panel.py +++ b/pandas/core/panel.py @@ -345,10 +345,7 @@ def _compare_constructor(self, other, func): def __unicode__(self): """ - Return a string representation for a particular Panel. - - Invoked by unicode(df) in py2 only. - Yields a Unicode String in both py2/py3. + Return a unicode string representation for a particular Panel. """ class_name = str(self.__class__) diff --git a/pandas/core/series.py b/pandas/core/series.py index 8a22765d85aec..65050db8c4380 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1374,10 +1374,7 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False): def __unicode__(self): """ - Return a string representation for a particular DataFrame. - - Invoked by unicode(df) in py2 only. Yields a Unicode String in both - py2/py3. + Return a unicode string representation for a particular DataFrame. """ buf = StringIO("") width, height = get_terminal_size() diff --git a/pandas/io/clipboard/clipboards.py b/pandas/io/clipboard/clipboards.py index b7bed084d72f1..3c8abe74912fd 100644 --- a/pandas/io/clipboard/clipboards.py +++ b/pandas/io/clipboard/clipboards.py @@ -33,11 +33,7 @@ def copy_gtk(text): def paste_gtk(): clipboardContents = gtk.Clipboard().wait_for_text() - # for python 2, returns None if the clipboard is blank. - if clipboardContents is None: - return '' - else: - return clipboardContents + return clipboardContents return copy_gtk, paste_gtk diff --git a/pandas/io/formats/printing.py b/pandas/io/formats/printing.py index 0e6366705c98a..bee66fcbfaa82 100644 --- a/pandas/io/formats/printing.py +++ b/pandas/io/formats/printing.py @@ -175,7 +175,7 @@ def pprint_thing(thing, _nest_lvl=0, escape_chars=None, default_escapes=False, Returns ------- - result - unicode object on py2, str on py3. Always Unicode. + result - unicode str """ diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 5d73b377838b6..56ba842fa26a2 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -1326,12 +1326,6 @@ def _validate_usecols_arg(usecols): usecols = set(usecols) - if usecols_dtype == "unicode": - # see gh-13253 - # - # Python 2.x compatibility - usecols = {col.encode("utf-8") for col in usecols} - return usecols, usecols_dtype return usecols, None diff --git a/pandas/tests/extension/json/array.py b/pandas/tests/extension/json/array.py index 45574262354f5..4b93f0e12e32a 100644 --- a/pandas/tests/extension/json/array.py +++ b/pandas/tests/extension/json/array.py @@ -27,12 +27,7 @@ class JSONDtype(ExtensionDtype): type = abc.Mapping name = 'json' - - try: - na_value = UserDict() - except AttributeError: - # source compatibility with Py2. - na_value = {} + na_value = UserDict() @classmethod def construct_array_type(cls): diff --git a/pandas/tests/extension/test_integer.py b/pandas/tests/extension/test_integer.py index a8dcabbb824d5..e9f96390821a6 100644 --- a/pandas/tests/extension/test_integer.py +++ b/pandas/tests/extension/test_integer.py @@ -113,10 +113,7 @@ def _check_op(self, s, op, other, op_name, exc=NotImplementedError): result = op(s, other) expected = s.combine(other, op) - if op_name == '__rdiv__': - # combine is not giving the correct result for this case - pytest.skip("skipping reverse div in python 2") - elif op_name in ('__rtruediv__', '__truediv__', '__div__'): + if op_name in ('__rtruediv__', '__truediv__', '__div__'): expected = expected.astype(float) if op_name == '__rtruediv__': # TODO reverse operators result in object dtype diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 116a12c1c520b..2a9246a5a9554 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -6,7 +6,6 @@ import math import operator import re -import sys import numpy as np import pytest @@ -414,9 +413,6 @@ def test_constructor_dtypes_datetime(self, tz_naive_fixture, attr, utc, index = index.tz_localize(tz_naive_fixture) dtype = index.dtype - # TODO(GH-24559): Remove the sys.modules and warnings - # not sure what this is from. It's Py2 only. - modules = [sys.modules['pandas.core.indexes.base']] if (tz_naive_fixture and attr == "asi8" and str(tz_naive_fixture) not in ('UTC', 'tzutc()', 'UTC+00:00')): ex_warn = FutureWarning @@ -425,8 +421,7 @@ def test_constructor_dtypes_datetime(self, tz_naive_fixture, attr, utc, # stacklevel is checked elsewhere. We don't do it here since # Index will have an frame, throwing off the expected. - with tm.assert_produces_warning(ex_warn, check_stacklevel=False, - clear=modules): + with tm.assert_produces_warning(ex_warn, check_stacklevel=False): result = klass(arg, tz=tz_naive_fixture) tm.assert_index_equal(result, index) diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index fbd71dfa8262b..c0b41691a67ef 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -49,8 +49,7 @@ def test_to_csv_defualt_encoding(self): df = DataFrame({'col': ["AAAAA", "ÄÄÄÄÄ", "ßßßßß", "聞聞聞聞聞"]}) with tm.ensure_clean('test.csv') as path: - # the default to_csv encoding in Python 2 is ascii, and that in - # Python 3 is uft-8. + # the default to_csv encoding is uft-8. df.to_csv(path) tm.assert_frame_equal(pd.read_csv(path, index_col=0), df) diff --git a/pandas/tests/io/parser/test_c_parser_only.py b/pandas/tests/io/parser/test_c_parser_only.py index 22157a742bacc..0b5fe1623699c 100644 --- a/pandas/tests/io/parser/test_c_parser_only.py +++ b/pandas/tests/io/parser/test_c_parser_only.py @@ -416,7 +416,7 @@ def test_read_nrows_large(c_parser_only): def test_float_precision_round_trip_with_text(c_parser_only): - # see gh-15140 - This should not segfault on Python 2.7+ + # see gh-15140 parser = c_parser_only df = parser.read_csv(StringIO("a"), header=None, float_precision="round_trip") diff --git a/pandas/tests/io/test_compression.py b/pandas/tests/io/test_compression.py index a3fb35f9f01f2..c0e19f07c148d 100644 --- a/pandas/tests/io/test_compression.py +++ b/pandas/tests/io/test_compression.py @@ -100,11 +100,6 @@ def test_series_compression_defaults_to_infer( def test_compression_warning(compression_only): # Assert that passing a file object to to_csv while explicitly specifying a # compression protocol triggers a RuntimeWarning, as per GH21227. - # Note that pytest has an issue that causes assert_produces_warning to fail - # in Python 2 if the warning has occurred in previous tests - # (see https://git.io/fNEBm & https://git.io/fNEBC). Hence, should this - # test fail in just Python 2 builds, it likely indicates that other tests - # are producing RuntimeWarnings, thereby triggering the pytest bug. df = pd.DataFrame(100 * [[0.123456, 0.234567, 0.567567], [12.32112, 123123.2, 321321.2]], columns=['X', 'Y', 'Z']) diff --git a/pandas/tests/io/test_pickle.py b/pandas/tests/io/test_pickle.py index b4e942fc086a9..872267e86d95f 100644 --- a/pandas/tests/io/test_pickle.py +++ b/pandas/tests/io/test_pickle.py @@ -67,15 +67,7 @@ def compare_element(result, expected, typ, version=None): def compare(data, vf, version): - # py3 compat when reading py2 pickle - try: - data = pd.read_pickle(vf) - except (ValueError) as e: - if 'unsupported pickle protocol:' in str(e): - # trying to read a py3 pickle in py2 - return - else: - raise + data = pd.read_pickle(vf) m = globals() for typ, dv in data.items(): diff --git a/scripts/merge-pr.py b/scripts/merge-pr.py index b9233abe56149..5c665faac5976 100755 --- a/scripts/merge-pr.py +++ b/scripts/merge-pr.py @@ -30,8 +30,6 @@ import sys import textwrap -from six.moves import input - PANDAS_HOME = '.' PROJECT_NAME = 'pandas' print("PANDAS_HOME = " + PANDAS_HOME)