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

Use PyCapsule for internal datetime functions #51525

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 40 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
431495b
initial file setup and build
WillAyd Feb 18, 2023
c3dca72
Building standalone impl
WillAyd Feb 18, 2023
d77a2ed
more build
WillAyd Feb 18, 2023
4525e77
linting
WillAyd Feb 18, 2023
782b971
more updates
WillAyd Feb 18, 2023
69abccd
Capsule location change
WillAyd Feb 19, 2023
69460bd
working import
WillAyd Feb 20, 2023
776f0f5
working imports?
WillAyd Feb 20, 2023
c4a05b5
moved lots
WillAyd Feb 20, 2023
a995ee2
Working impl
WillAyd Feb 21, 2023
05e28ad
styling
WillAyd Feb 21, 2023
d938374
import cleanups
WillAyd Feb 21, 2023
df687b3
revert init change
WillAyd Feb 21, 2023
a26f312
cleanups
WillAyd Feb 21, 2023
96b6f96
isort fixups
WillAyd Feb 21, 2023
7b28333
api test fix
WillAyd Feb 21, 2023
ccea2b3
removed unneeded tokenizer add
WillAyd Feb 21, 2023
2bf7264
Hacked together parser capsule
WillAyd Feb 26, 2023
418910d
Symbol cleanups
WillAyd Feb 26, 2023
a4f7e1a
Resolved all undefined symbols in parsers.pyx
WillAyd Feb 26, 2023
ad1d149
IO callbacks restored
WillAyd Feb 26, 2023
5887254
Fix build and test failures
WillAyd Feb 26, 2023
138ea0d
Try relative imports for MSFT compat
WillAyd Feb 26, 2023
679d03d
try py_ssize_t_clean macro
WillAyd Feb 26, 2023
7c4e365
Removed double tokenizer include
WillAyd Feb 26, 2023
5aee18a
removed unneeded include path
WillAyd Feb 26, 2023
a0523be
more cleanups
WillAyd Feb 27, 2023
554d701
noexcept
WillAyd Feb 27, 2023
726d93d
signature cleanup
WillAyd Feb 27, 2023
d2fe542
simplify parser impl
WillAyd Feb 28, 2023
49a2739
retain np_datetime_string license
WillAyd Feb 28, 2023
3981ec2
retained old file structure where possible
WillAyd Feb 28, 2023
fb75100
Commited C file
WillAyd Feb 28, 2023
f51e7f4
Removed erroneous comments
WillAyd Mar 2, 2023
709bf6c
Merge branch 'main' into np-datetime-capsule
WillAyd Mar 2, 2023
f4dac4f
graft pd_parser.c
WillAyd Mar 6, 2023
7fd0a49
Merge branch 'main' into np-datetime-capsule
WillAyd Mar 6, 2023
12179c7
graft -> include
WillAyd Mar 6, 2023
67f5445
Merge remote-tracking branch 'upstream/main' into np-datetime-capsule
WillAyd Mar 9, 2023
9271ce3
Merge branch 'main' into np-datetime-capsule
WillAyd Mar 11, 2023
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
more updates
  • Loading branch information
WillAyd committed Feb 18, 2023
commit 782b9718897d93ac9df7a04ac7c12c42ac4ee1c0
1 change: 1 addition & 0 deletions 1 pandas/_libs/missing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ from pandas._libs.tslibs.np_datetime cimport (
get_datetime64_unit,
get_datetime64_value,
get_timedelta64_value,
import_pandas_datetime
)

from pandas._libs.ops_dispatch import maybe_dispatch_ufunc_to_dunder_op
Expand Down
1 change: 1 addition & 0 deletions 1 pandas/_libs/src/ujson/python/date_conversions.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The full license is in the LICENSE file, distributed with this software.

#include "date_conversions.h"
#include <../../../tslibs/src/datetime/np_datetime.h>
#include <../../../tslibs/src/datetime/pd_datetime.h>
#include <../../../tslibs/src/datetime/np_datetime_strings.h>

/*
Expand Down
2 changes: 2 additions & 0 deletions 2 pandas/_libs/src/ujson/python/ujson.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Numeric decoder derived from TCL library
#include <Python.h>
#define PY_ARRAY_UNIQUE_SYMBOL UJSON_NUMPY
#include "numpy/arrayobject.h"
#include <../../../tslibs/src/datetime/pd_datetime.h>

/* objToJSON */
PyObject *objToJSON(PyObject *self, PyObject *args, PyObject *kwargs);
Expand Down Expand Up @@ -447,5 +448,6 @@ PyMODINIT_FUNC PyInit_json(void) {
}
*/

PandasDateTime_IMPORT;
return module;
}
5 changes: 4 additions & 1 deletion 5 pandas/_libs/tslibs/np_datetime.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ cdef extern from "src/datetime/pd_datetime.h":
void pandas_datetime_to_datetimestruct(npy_datetime val,
NPY_DATETIMEUNIT fr,
npy_datetimestruct *result) nogil
void PandasDateTime_IMPORT()

PandasDateTime_IMPORT
# You must call this before using the PandasDateTime CAPI functions
cdef inline void import_pandas_datetime():
PandasDateTime_IMPORT

cdef bint cmp_scalar(int64_t lhs, int64_t rhs, int op) except -1

Expand Down
101 changes: 0 additions & 101 deletions 101 pandas/_libs/tslibs/src/datetime/np_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,107 +444,6 @@ int convert_pydatetime_to_datetimestruct(PyObject *dtobj,
return 0;
}


/*
* Converts a datetime from a datetimestruct to a datetime based
* on a metadata unit. The date is assumed to be valid.
*/
npy_datetime npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT base,
const npy_datetimestruct *dts) {
npy_datetime ret;

if (base == NPY_FR_Y) {
/* Truncate to the year */
ret = dts->year - 1970;
} else if (base == NPY_FR_M) {
/* Truncate to the month */
ret = 12 * (dts->year - 1970) + (dts->month - 1);
} else {
/* Otherwise calculate the number of days to start */
npy_int64 days = get_datetimestruct_days(dts);

switch (base) {
case NPY_FR_W:
/* Truncate to weeks */
if (days >= 0) {
ret = days / 7;
} else {
ret = (days - 6) / 7;
}
break;
case NPY_FR_D:
ret = days;
break;
case NPY_FR_h:
ret = days * 24 + dts->hour;
break;
case NPY_FR_m:
ret = (days * 24 + dts->hour) * 60 + dts->min;
break;
case NPY_FR_s:
ret = ((days * 24 + dts->hour) * 60 + dts->min) * 60 + dts->sec;
break;
case NPY_FR_ms:
ret = (((days * 24 + dts->hour) * 60 + dts->min) * 60 +
dts->sec) *
1000 +
dts->us / 1000;
break;
case NPY_FR_us:
ret = (((days * 24 + dts->hour) * 60 + dts->min) * 60 +
dts->sec) *
1000000 +
dts->us;
break;
case NPY_FR_ns:
ret = ((((days * 24 + dts->hour) * 60 + dts->min) * 60 +
dts->sec) *
1000000 +
dts->us) *
1000 +
dts->ps / 1000;
break;
case NPY_FR_ps:
ret = ((((days * 24 + dts->hour) * 60 + dts->min) * 60 +
dts->sec) *
1000000 +
dts->us) *
1000000 +
dts->ps;
break;
case NPY_FR_fs:
/* only 2.6 hours */
ret = (((((days * 24 + dts->hour) * 60 + dts->min) * 60 +
dts->sec) *
1000000 +
dts->us) *
1000000 +
dts->ps) *
1000 +
dts->as / 1000;
break;
case NPY_FR_as:
/* only 9.2 secs */
ret = (((((days * 24 + dts->hour) * 60 + dts->min) * 60 +
dts->sec) *
1000000 +
dts->us) *
1000000 +
dts->ps) *
1000000 +
dts->as;
break;
default:
/* Something got corrupted */
PyErr_SetString(
PyExc_ValueError,
"NumPy datetime metadata with corrupt unit value");
return -1;
}
}
return ret;
}

/*
* Port numpy#13188 https://github.com/numpy/numpy/pull/13188/
*
Expand Down
3 changes: 0 additions & 3 deletions 3 pandas/_libs/tslibs/src/datetime/np_datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ PyObject *extract_utc_offset(PyObject *obj);
int convert_pydatetime_to_datetimestruct(PyObject *dtobj,
npy_datetimestruct *out);

npy_datetime npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT base,
const npy_datetimestruct *dts);

void pandas_datetime_to_datetimestruct(npy_datetime val, NPY_DATETIMEUNIT fr,
npy_datetimestruct *result);

Expand Down
3 changes: 3 additions & 0 deletions 3 pandas/_libs/tslibs/src/datetime/pd_datetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ extern "C" {

#define PandasDateTime_IMPORT \
PandasDateTimeAPI = (PandasDateTime_CAPI *)PyCapsule_Import(PandasDateTime_CAPSULE_NAME, 0)

#define npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT, npy_datetimestruct) \
PandasDateTimeAPI->npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT, npy_datetimestruct)
#endif /* !defined(_PANDAS_DATETIME_IMPL) */

#ifdef __cplusplus
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.