Skip to content

Commit 0af4dd6

Browse files
lithomas1yehoshuadimarsky
authored andcommitted
CLN: Remove Python 2 compat in np_datetime.c (pandas-dev#45606)
1 parent 314d657 commit 0af4dd6

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

pandas/_libs/tslibs/src/datetime/np_datetime.c

+8-12
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
2727
#include <numpy/ndarraytypes.h>
2828
#include "np_datetime.h"
2929

30-
#if PY_MAJOR_VERSION >= 3
31-
#define PyInt_AsLong PyLong_AsLong
32-
#endif // PyInt_AsLong
33-
3430
const npy_datetimestruct _NS_MIN_DTS = {
3531
1677, 9, 21, 0, 12, 43, 145224, 193000, 0};
3632
const npy_datetimestruct _NS_MAX_DTS = {
@@ -330,9 +326,9 @@ int convert_pydatetime_to_datetimestruct(PyObject *dtobj,
330326
out->month = 1;
331327
out->day = 1;
332328

333-
out->year = PyInt_AsLong(PyObject_GetAttrString(obj, "year"));
334-
out->month = PyInt_AsLong(PyObject_GetAttrString(obj, "month"));
335-
out->day = PyInt_AsLong(PyObject_GetAttrString(obj, "day"));
329+
out->year = PyLong_AsLong(PyObject_GetAttrString(obj, "year"));
330+
out->month = PyLong_AsLong(PyObject_GetAttrString(obj, "month"));
331+
out->day = PyLong_AsLong(PyObject_GetAttrString(obj, "day"));
336332

337333
// TODO(anyone): If we can get PyDateTime_IMPORT to work, we could use
338334
// PyDateTime_Check here, and less verbose attribute lookups.
@@ -345,10 +341,10 @@ int convert_pydatetime_to_datetimestruct(PyObject *dtobj,
345341
return 0;
346342
}
347343

348-
out->hour = PyInt_AsLong(PyObject_GetAttrString(obj, "hour"));
349-
out->min = PyInt_AsLong(PyObject_GetAttrString(obj, "minute"));
350-
out->sec = PyInt_AsLong(PyObject_GetAttrString(obj, "second"));
351-
out->us = PyInt_AsLong(PyObject_GetAttrString(obj, "microsecond"));
344+
out->hour = PyLong_AsLong(PyObject_GetAttrString(obj, "hour"));
345+
out->min = PyLong_AsLong(PyObject_GetAttrString(obj, "minute"));
346+
out->sec = PyLong_AsLong(PyObject_GetAttrString(obj, "second"));
347+
out->us = PyLong_AsLong(PyObject_GetAttrString(obj, "microsecond"));
352348

353349
/* Apply the time zone offset if datetime obj is tz-aware */
354350
if (PyObject_HasAttrString((PyObject*)obj, "tzinfo")) {
@@ -384,7 +380,7 @@ int convert_pydatetime_to_datetimestruct(PyObject *dtobj,
384380
Py_DECREF(tmp);
385381
return -1;
386382
}
387-
seconds_offset = PyInt_AsLong(tmp_int);
383+
seconds_offset = PyLong_AsLong(tmp_int);
388384
if (seconds_offset == -1 && PyErr_Occurred()) {
389385
Py_DECREF(tmp_int);
390386
Py_DECREF(tmp);

0 commit comments

Comments
 (0)