Skip to content

Commit 4814a28

Browse files
authored
CLN: Remove PY2/3 references in pandas/util (pandas-dev#25962)
xref pandas-devgh-25725.
1 parent f90f4aa commit 4814a28

File tree

5 files changed

+22
-81
lines changed

5 files changed

+22
-81
lines changed

pandas/util/_decorators.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import warnings
55

66
from pandas._libs.properties import cache_readonly # noqa
7-
from pandas.compat import PY2, signature
7+
from pandas.compat import signature
88

99

1010
def deprecate(name, alternative, version, alt_name=None,
@@ -197,22 +197,21 @@ def decorate(func):
197197
def wrapper(*args, **kwargs):
198198
return func(*args, **kwargs)
199199

200-
if not PY2:
201-
kind = inspect.Parameter.POSITIONAL_OR_KEYWORD
202-
params = [
203-
inspect.Parameter('self', kind),
204-
inspect.Parameter(name, kind, default=None),
205-
inspect.Parameter('index', kind, default=None),
206-
inspect.Parameter('columns', kind, default=None),
207-
inspect.Parameter('axis', kind, default=None),
208-
]
200+
kind = inspect.Parameter.POSITIONAL_OR_KEYWORD
201+
params = [
202+
inspect.Parameter('self', kind),
203+
inspect.Parameter(name, kind, default=None),
204+
inspect.Parameter('index', kind, default=None),
205+
inspect.Parameter('columns', kind, default=None),
206+
inspect.Parameter('axis', kind, default=None),
207+
]
209208

210-
for pname, default in extra_params:
211-
params.append(inspect.Parameter(pname, kind, default=default))
209+
for pname, default in extra_params:
210+
params.append(inspect.Parameter(pname, kind, default=default))
212211

213-
sig = inspect.Signature(params)
212+
sig = inspect.Signature(params)
214213

215-
func.__signature__ = sig
214+
func.__signature__ = sig
216215
return wrapper
217216
return decorate
218217

pandas/util/_test_decorators.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_foo():
2727

2828
import pytest
2929

30-
from pandas.compat import PY3, is_platform_32bit, is_platform_windows
30+
from pandas.compat import is_platform_32bit, is_platform_windows
3131
from pandas.compat.numpy import _np_version_under1p15
3232

3333
from pandas.core.computation.expressions import (
@@ -141,9 +141,8 @@ def decorated_func(func):
141141
reason="skipping for 32 bit")
142142
skip_if_windows = pytest.mark.skipif(is_platform_windows(),
143143
reason="Running on Windows")
144-
skip_if_windows_python_3 = pytest.mark.skipif(is_platform_windows() and PY3,
145-
reason=("not used on python3/"
146-
"win32"))
144+
skip_if_windows_python_3 = pytest.mark.skipif(is_platform_windows(),
145+
reason="not used on win32")
147146
skip_if_has_locale = pytest.mark.skipif(_skip_if_has_locale(),
148147
reason="Specific locale is set {lang}"
149148
.format(lang=locale.getlocale()[0]))

pandas/util/_validators.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def validate_axis_style_args(data, args, kwargs, arg_name, method_name):
237237
Parameters
238238
----------
239239
data : DataFrame or Panel
240-
arg : tuple
240+
args : tuple
241241
All positional arguments from the user
242242
kwargs : dict
243243
All keyword arguments from the user
@@ -261,7 +261,7 @@ def validate_axis_style_args(data, args, kwargs, arg_name, method_name):
261261
... 'mapper', 'rename')
262262
{'columns': <function id>, 'index': <method 'upper' of 'str' objects>}
263263
"""
264-
# TODO(PY3): Change to keyword-only args and remove all this
264+
# TODO: Change to keyword-only args and remove all this
265265

266266
out = {}
267267
# Goal: fill 'out' with index/columns-style arguments

pandas/util/move.c

+2-55
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@ The full license is in the LICENSE file, distributed with this software.
99

1010
#include <Python.h>
1111

12-
#define COMPILING_IN_PY2 (PY_VERSION_HEX <= 0x03000000)
13-
14-
#if !COMPILING_IN_PY2
1512
/* alias this because it is not aliased in Python 3 */
1613
#define PyString_CheckExact PyBytes_CheckExact
1714
#define PyString_AS_STRING PyBytes_AS_STRING
1815
#define PyString_GET_SIZE PyBytes_GET_SIZE
1916

2017
/* in python 3, we cannot intern bytes objects so this is always false */
2118
#define PyString_CHECK_INTERNED(cs) 0
22-
#endif // !COMPILING_IN_PY2
2319

2420
#ifndef Py_TPFLAGS_HAVE_GETCHARBUFFER
2521
#define Py_TPFLAGS_HAVE_GETCHARBUFFER 0
@@ -55,45 +51,11 @@ stolenbuf_getbuffer(stolenbufobject *self, Py_buffer *view, int flags) {
5551
flags);
5652
}
5753

58-
#if COMPILING_IN_PY2
59-
60-
static Py_ssize_t
61-
stolenbuf_getreadwritebuf(stolenbufobject *self,
62-
Py_ssize_t segment, void **out) {
63-
if (segment != 0) {
64-
PyErr_SetString(PyExc_SystemError,
65-
"accessing non-existent string segment");
66-
return -1;
67-
}
68-
*out = PyString_AS_STRING(self->invalid_bytes);
69-
return PyString_GET_SIZE(self->invalid_bytes);
70-
}
71-
72-
static Py_ssize_t
73-
stolenbuf_getsegcount(stolenbufobject *self, Py_ssize_t *len) {
74-
if (len) {
75-
*len = PyString_GET_SIZE(self->invalid_bytes);
76-
}
77-
return 1;
78-
}
79-
80-
static PyBufferProcs stolenbuf_as_buffer = {
81-
(readbufferproc) stolenbuf_getreadwritebuf,
82-
(writebufferproc) stolenbuf_getreadwritebuf,
83-
(segcountproc) stolenbuf_getsegcount,
84-
(charbufferproc) stolenbuf_getreadwritebuf,
85-
(getbufferproc) stolenbuf_getbuffer,
86-
};
87-
88-
#else // Python 3
89-
9054
static PyBufferProcs stolenbuf_as_buffer = {
9155
(getbufferproc) stolenbuf_getbuffer,
9256
NULL,
9357
};
9458

95-
#endif // COMPILING_IN_PY2
96-
9759
PyDoc_STRVAR(stolenbuf_doc,
9860
"A buffer that is wrapping a stolen bytes object's buffer.");
9961

@@ -200,15 +162,13 @@ static PyMethodDef methods[] = {
200162

201163
#define MODULE_NAME "pandas.util._move"
202164

203-
#if !COMPILING_IN_PY2
204165
static PyModuleDef move_module = {
205166
PyModuleDef_HEAD_INIT,
206167
MODULE_NAME,
207168
NULL,
208169
-1,
209170
methods,
210171
};
211-
#endif // !COMPILING_IN_PY2
212172

213173
PyDoc_STRVAR(
214174
badmove_doc,
@@ -225,14 +185,8 @@ PyDoc_STRVAR(
225185
"pandas.util._move.move_into_mutable_buffer\n");
226186

227187
PyMODINIT_FUNC
228-
#if !COMPILING_IN_PY2
229188
#define ERROR_RETURN NULL
230-
PyInit__move(void)
231-
#else
232-
#define ERROR_RETURN
233-
init_move(void)
234-
#endif // !COMPILING_IN_PY2
235-
{
189+
PyInit__move(void) {
236190
PyObject *m;
237191

238192
if (!(badmove = PyErr_NewExceptionWithDoc("pandas.util._move.BadMove",
@@ -246,12 +200,7 @@ init_move(void)
246200
return ERROR_RETURN;
247201
}
248202

249-
#if !COMPILING_IN_PY2
250-
if (!(m = PyModule_Create(&move_module)))
251-
#else
252-
if (!(m = Py_InitModule(MODULE_NAME, methods)))
253-
#endif // !COMPILING_IN_PY2
254-
{
203+
if (!(m = PyModule_Create(&move_module))) {
255204
return ERROR_RETURN;
256205
}
257206

@@ -267,7 +216,5 @@ init_move(void)
267216
return ERROR_RETURN;
268217
}
269218

270-
#if !COMPILING_IN_PY2
271219
return m;
272-
#endif // !COMPILING_IN_PY2
273220
}

pandas/util/testing.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222

2323
from pandas._libs import testing as _testing
2424
import pandas.compat as compat
25-
from pandas.compat import (
26-
PY3, httplib, lmap, lrange, lzip, raise_with_traceback)
25+
from pandas.compat import httplib, lmap, lrange, lzip, raise_with_traceback
2726

2827
from pandas.core.dtypes.common import (
2928
is_bool, is_categorical_dtype, is_datetime64_dtype, is_datetime64tz_dtype,
@@ -2048,10 +2047,7 @@ def dec(f):
20482047
# servers.
20492048

20502049
# and conditionally raise on these exception types
2051-
_network_error_classes = (IOError, httplib.HTTPException)
2052-
2053-
if PY3:
2054-
_network_error_classes += (TimeoutError,) # noqa
2050+
_network_error_classes = (IOError, httplib.HTTPException, TimeoutError)
20552051

20562052

20572053
def can_connect(url, error_classes=_network_error_classes):

0 commit comments

Comments
 (0)