diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index e92051ebbea9a..c3e127a673ac6 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -4,7 +4,7 @@ import warnings from pandas._libs.properties import cache_readonly # noqa -from pandas.compat import PY2, signature +from pandas.compat import signature def deprecate(name, alternative, version, alt_name=None, @@ -197,22 +197,21 @@ def decorate(func): def wrapper(*args, **kwargs): return func(*args, **kwargs) - if not PY2: - kind = inspect.Parameter.POSITIONAL_OR_KEYWORD - params = [ - inspect.Parameter('self', kind), - inspect.Parameter(name, kind, default=None), - inspect.Parameter('index', kind, default=None), - inspect.Parameter('columns', kind, default=None), - inspect.Parameter('axis', kind, default=None), - ] + kind = inspect.Parameter.POSITIONAL_OR_KEYWORD + params = [ + inspect.Parameter('self', kind), + inspect.Parameter(name, kind, default=None), + inspect.Parameter('index', kind, default=None), + inspect.Parameter('columns', kind, default=None), + inspect.Parameter('axis', kind, default=None), + ] - for pname, default in extra_params: - params.append(inspect.Parameter(pname, kind, default=default)) + for pname, default in extra_params: + params.append(inspect.Parameter(pname, kind, default=default)) - sig = inspect.Signature(params) + sig = inspect.Signature(params) - func.__signature__ = sig + func.__signature__ = sig return wrapper return decorate diff --git a/pandas/util/_test_decorators.py b/pandas/util/_test_decorators.py index 7266833f8bbde..6a1a2546c085d 100644 --- a/pandas/util/_test_decorators.py +++ b/pandas/util/_test_decorators.py @@ -27,7 +27,7 @@ def test_foo(): import pytest -from pandas.compat import PY3, is_platform_32bit, is_platform_windows +from pandas.compat import is_platform_32bit, is_platform_windows from pandas.compat.numpy import _np_version_under1p15 from pandas.core.computation.expressions import ( @@ -141,9 +141,8 @@ def decorated_func(func): reason="skipping for 32 bit") skip_if_windows = pytest.mark.skipif(is_platform_windows(), reason="Running on Windows") -skip_if_windows_python_3 = pytest.mark.skipif(is_platform_windows() and PY3, - reason=("not used on python3/" - "win32")) +skip_if_windows_python_3 = pytest.mark.skipif(is_platform_windows(), + reason="not used on win32") skip_if_has_locale = pytest.mark.skipif(_skip_if_has_locale(), reason="Specific locale is set {lang}" .format(lang=locale.getlocale()[0])) diff --git a/pandas/util/_validators.py b/pandas/util/_validators.py index 1171478de2eb4..d392a7709061b 100644 --- a/pandas/util/_validators.py +++ b/pandas/util/_validators.py @@ -237,7 +237,7 @@ def validate_axis_style_args(data, args, kwargs, arg_name, method_name): Parameters ---------- data : DataFrame or Panel - arg : tuple + args : tuple All positional arguments from the user kwargs : dict All keyword arguments from the user @@ -261,7 +261,7 @@ def validate_axis_style_args(data, args, kwargs, arg_name, method_name): ... 'mapper', 'rename') {'columns': , 'index': } """ - # TODO(PY3): Change to keyword-only args and remove all this + # TODO: Change to keyword-only args and remove all this out = {} # Goal: fill 'out' with index/columns-style arguments diff --git a/pandas/util/move.c b/pandas/util/move.c index 188d7b79b35d2..f561f9081439d 100644 --- a/pandas/util/move.c +++ b/pandas/util/move.c @@ -9,9 +9,6 @@ The full license is in the LICENSE file, distributed with this software. #include -#define COMPILING_IN_PY2 (PY_VERSION_HEX <= 0x03000000) - -#if !COMPILING_IN_PY2 /* alias this because it is not aliased in Python 3 */ #define PyString_CheckExact PyBytes_CheckExact #define PyString_AS_STRING PyBytes_AS_STRING @@ -19,7 +16,6 @@ The full license is in the LICENSE file, distributed with this software. /* in python 3, we cannot intern bytes objects so this is always false */ #define PyString_CHECK_INTERNED(cs) 0 -#endif // !COMPILING_IN_PY2 #ifndef Py_TPFLAGS_HAVE_GETCHARBUFFER #define Py_TPFLAGS_HAVE_GETCHARBUFFER 0 @@ -55,45 +51,11 @@ stolenbuf_getbuffer(stolenbufobject *self, Py_buffer *view, int flags) { flags); } -#if COMPILING_IN_PY2 - -static Py_ssize_t -stolenbuf_getreadwritebuf(stolenbufobject *self, - Py_ssize_t segment, void **out) { - if (segment != 0) { - PyErr_SetString(PyExc_SystemError, - "accessing non-existent string segment"); - return -1; - } - *out = PyString_AS_STRING(self->invalid_bytes); - return PyString_GET_SIZE(self->invalid_bytes); -} - -static Py_ssize_t -stolenbuf_getsegcount(stolenbufobject *self, Py_ssize_t *len) { - if (len) { - *len = PyString_GET_SIZE(self->invalid_bytes); - } - return 1; -} - -static PyBufferProcs stolenbuf_as_buffer = { - (readbufferproc) stolenbuf_getreadwritebuf, - (writebufferproc) stolenbuf_getreadwritebuf, - (segcountproc) stolenbuf_getsegcount, - (charbufferproc) stolenbuf_getreadwritebuf, - (getbufferproc) stolenbuf_getbuffer, -}; - -#else // Python 3 - static PyBufferProcs stolenbuf_as_buffer = { (getbufferproc) stolenbuf_getbuffer, NULL, }; -#endif // COMPILING_IN_PY2 - PyDoc_STRVAR(stolenbuf_doc, "A buffer that is wrapping a stolen bytes object's buffer."); @@ -200,7 +162,6 @@ static PyMethodDef methods[] = { #define MODULE_NAME "pandas.util._move" -#if !COMPILING_IN_PY2 static PyModuleDef move_module = { PyModuleDef_HEAD_INIT, MODULE_NAME, @@ -208,7 +169,6 @@ static PyModuleDef move_module = { -1, methods, }; -#endif // !COMPILING_IN_PY2 PyDoc_STRVAR( badmove_doc, @@ -225,14 +185,8 @@ PyDoc_STRVAR( "pandas.util._move.move_into_mutable_buffer\n"); PyMODINIT_FUNC -#if !COMPILING_IN_PY2 #define ERROR_RETURN NULL -PyInit__move(void) -#else -#define ERROR_RETURN -init_move(void) -#endif // !COMPILING_IN_PY2 -{ +PyInit__move(void) { PyObject *m; if (!(badmove = PyErr_NewExceptionWithDoc("pandas.util._move.BadMove", @@ -246,12 +200,7 @@ init_move(void) return ERROR_RETURN; } -#if !COMPILING_IN_PY2 - if (!(m = PyModule_Create(&move_module))) -#else - if (!(m = Py_InitModule(MODULE_NAME, methods))) -#endif // !COMPILING_IN_PY2 - { + if (!(m = PyModule_Create(&move_module))) { return ERROR_RETURN; } @@ -267,7 +216,5 @@ init_move(void) return ERROR_RETURN; } -#if !COMPILING_IN_PY2 return m; -#endif // !COMPILING_IN_PY2 } diff --git a/pandas/util/testing.py b/pandas/util/testing.py index e4167e0ab7066..633142829dc1b 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -22,8 +22,7 @@ from pandas._libs import testing as _testing import pandas.compat as compat -from pandas.compat import ( - PY3, httplib, lmap, lrange, lzip, raise_with_traceback) +from pandas.compat import httplib, lmap, lrange, lzip, raise_with_traceback from pandas.core.dtypes.common import ( is_bool, is_categorical_dtype, is_datetime64_dtype, is_datetime64tz_dtype, @@ -2048,10 +2047,7 @@ def dec(f): # servers. # and conditionally raise on these exception types -_network_error_classes = (IOError, httplib.HTTPException) - -if PY3: - _network_error_classes += (TimeoutError,) # noqa +_network_error_classes = (IOError, httplib.HTTPException, TimeoutError) def can_connect(url, error_classes=_network_error_classes):