Skip to content

CLN: Remove PY2/3 references in pandas/util #25962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions pandas/util/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions pandas/util/_test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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]))
Expand Down
4 changes: 2 additions & 2 deletions pandas/util/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -261,7 +261,7 @@ def validate_axis_style_args(data, args, kwargs, arg_name, method_name):
... 'mapper', 'rename')
{'columns': <function id>, 'index': <method 'upper' of 'str' objects>}
"""
# 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
Expand Down
57 changes: 2 additions & 55 deletions pandas/util/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ The full license is in the LICENSE file, distributed with this software.

#include <Python.h>

#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
#define PyString_GET_SIZE PyBytes_GET_SIZE

/* 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
Expand Down Expand Up @@ -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.");

Expand Down Expand Up @@ -200,15 +162,13 @@ static PyMethodDef methods[] = {

#define MODULE_NAME "pandas.util._move"

#if !COMPILING_IN_PY2
static PyModuleDef move_module = {
PyModuleDef_HEAD_INIT,
MODULE_NAME,
NULL,
-1,
methods,
};
#endif // !COMPILING_IN_PY2

PyDoc_STRVAR(
badmove_doc,
Expand All @@ -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",
Expand All @@ -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;
}

Expand All @@ -267,7 +216,5 @@ init_move(void)
return ERROR_RETURN;
}

#if !COMPILING_IN_PY2
return m;
#endif // !COMPILING_IN_PY2
}
8 changes: 2 additions & 6 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down