Skip to content

CLN: Remove Python 2 compat in np_datetime.c #45606

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
Jan 26, 2022
Merged
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
20 changes: 8 additions & 12 deletions pandas/_libs/tslibs/src/datetime/np_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
#include <numpy/ndarraytypes.h>
#include "np_datetime.h"

#if PY_MAJOR_VERSION >= 3
#define PyInt_AsLong PyLong_AsLong
#endif // PyInt_AsLong

const npy_datetimestruct _NS_MIN_DTS = {
1677, 9, 21, 0, 12, 43, 145224, 193000, 0};
const npy_datetimestruct _NS_MAX_DTS = {
Expand Down Expand Up @@ -330,9 +326,9 @@ int convert_pydatetime_to_datetimestruct(PyObject *dtobj,
out->month = 1;
out->day = 1;

out->year = PyInt_AsLong(PyObject_GetAttrString(obj, "year"));
out->month = PyInt_AsLong(PyObject_GetAttrString(obj, "month"));
out->day = PyInt_AsLong(PyObject_GetAttrString(obj, "day"));
out->year = PyLong_AsLong(PyObject_GetAttrString(obj, "year"));
out->month = PyLong_AsLong(PyObject_GetAttrString(obj, "month"));
out->day = PyLong_AsLong(PyObject_GetAttrString(obj, "day"));

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

out->hour = PyInt_AsLong(PyObject_GetAttrString(obj, "hour"));
out->min = PyInt_AsLong(PyObject_GetAttrString(obj, "minute"));
out->sec = PyInt_AsLong(PyObject_GetAttrString(obj, "second"));
out->us = PyInt_AsLong(PyObject_GetAttrString(obj, "microsecond"));
out->hour = PyLong_AsLong(PyObject_GetAttrString(obj, "hour"));
out->min = PyLong_AsLong(PyObject_GetAttrString(obj, "minute"));
out->sec = PyLong_AsLong(PyObject_GetAttrString(obj, "second"));
out->us = PyLong_AsLong(PyObject_GetAttrString(obj, "microsecond"));

/* Apply the time zone offset if datetime obj is tz-aware */
if (PyObject_HasAttrString((PyObject*)obj, "tzinfo")) {
Expand Down Expand Up @@ -384,7 +380,7 @@ int convert_pydatetime_to_datetimestruct(PyObject *dtobj,
Py_DECREF(tmp);
return -1;
}
seconds_offset = PyInt_AsLong(tmp_int);
seconds_offset = PyLong_AsLong(tmp_int);
if (seconds_offset == -1 && PyErr_Occurred()) {
Py_DECREF(tmp_int);
Py_DECREF(tmp);
Expand Down