Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

REF: use datetime C API instead of getattrs #51368

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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Simplify
  • Loading branch information
jbrockmendel committed Feb 14, 2023
commit d3bfd4966b5bced54fd795dd80ddae4f418aa11d
19 changes: 2 additions & 17 deletions 19 pandas/_libs/src/ujson/python/date_conversions.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,7 @@ char *PyDateTimeToIso(PyObject *obj, NPY_DATETIMEUNIT base,
npy_datetimestruct dts;
int ret;

PyDateTime_IMPORT;
if (!PyDate_Check(obj)) {
PyErr_SetString(PyExc_TypeError, "Expected date object");
return NULL;
}
PyDateTime_Date *dtobj = (PyDateTime_Date*)obj;

ret = convert_pydatetime_to_datetimestruct(dtobj, &dts);
ret = convert_pydatetime_to_datetimestruct(obj, &dts);
if (ret != 0) {
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_ValueError,
Expand Down Expand Up @@ -128,15 +121,7 @@ npy_datetime PyDateTimeToEpoch(PyObject *dt, NPY_DATETIMEUNIT base) {
npy_datetimestruct dts;
int ret;

PyDateTime_IMPORT;

if (!PyDate_Check(dt)) {
PyErr_SetString(PyExc_TypeError, "Expected date object");
// return NULL;
}
PyDateTime_Date *dtobj = (PyDateTime_Date*)dt;

ret = convert_pydatetime_to_datetimestruct(dtobj, &dts);
ret = convert_pydatetime_to_datetimestruct(dt, &dts);
if (ret != 0) {
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_ValueError,
Expand Down
20 changes: 13 additions & 7 deletions 20 pandas/_libs/tslibs/src/datetime/np_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ PyObject *extract_utc_offset(PyObject *obj) {
* Returns -1 on error, 0 on success, and 1 (with no error set)
* if obj doesn't have the needed date or datetime attributes.
*/
int convert_pydatetime_to_datetimestruct(PyDateTime_Date *dtobj,
int convert_pydatetime_to_datetimestruct(PyObject *dtobj,
npy_datetimestruct *out) {
// Assumes that obj is a valid datetime object
PyObject *tmp;
Expand All @@ -383,13 +383,19 @@ int convert_pydatetime_to_datetimestruct(PyDateTime_Date *dtobj,

PyDateTime_IMPORT;

out->year = PyDateTime_GET_YEAR(dtobj);
out->month = PyDateTime_GET_MONTH(dtobj);
out->day = PyDateTime_GET_DAY(dtobj);
out->hour = PyDateTime_DATE_GET_HOUR(dtobj);
if (!PyDate_Check(dtobj)) {
PyErr_SetString(PyExc_TypeError, "Expected date object");
return NULL;
}
PyDateTime_Date *dateobj = (PyDateTime_Date*)dtobj;

out->year = PyDateTime_GET_YEAR(dateobj);
out->month = PyDateTime_GET_MONTH(dateobj);
out->day = PyDateTime_GET_DAY(dateobj);
out->hour = PyDateTime_DATE_GET_HOUR(dateobj);

if (PyDateTime_Check(dtobj)) {
PyDateTime_DateTime* obj = (PyDateTime_DateTime*)dtobj;
if (PyDateTime_Check(dateobj)) {
PyDateTime_DateTime* obj = (PyDateTime_DateTime*)dateobj;
out->min = PyDateTime_DATE_GET_MINUTE(obj);
out->sec = PyDateTime_DATE_GET_SECOND(obj);
out->us = PyDateTime_DATE_GET_MICROSECOND(obj);
Expand Down
4 changes: 1 addition & 3 deletions 4 pandas/_libs/tslibs/src/datetime/np_datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt

#include <numpy/ndarraytypes.h>

#include "datetime.h"

typedef struct {
npy_int64 days;
npy_int32 hrs, min, sec, ms, us, ns, seconds, microseconds, nanoseconds;
Expand Down Expand Up @@ -52,7 +50,7 @@ extern const npy_datetimestruct _M_MAX_DTS;

PyObject *extract_utc_offset(PyObject *obj);

int convert_pydatetime_to_datetimestruct(PyDateTime_Date *dtobj,
int convert_pydatetime_to_datetimestruct(PyObject *dtobj,
npy_datetimestruct *out);

npy_datetime npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT base,
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.