Skip to content

Revert "Use PyCapsule for internal datetime functions" #51951

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
Mar 14, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,3 @@ prune pandas/tests/io/parser/data
# Selectively re-add *.cxx files that were excluded above
graft pandas/_libs/src
graft pandas/_libs/tslibs/src
include pandas/_libs/pd_parser.h
include pandas/_libs/pd_parser.c
5 changes: 0 additions & 5 deletions pandas/_libs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
]


# Below imports needs to happen first to ensure pandas top level
# module gets monkeypatched with the pandas_datetime_CAPI
# see pandas_datetime_exec in pd_datetime.c
import pandas._libs.pandas_parser # noqa # isort: skip # type: ignore[reportUnusedImport]
import pandas._libs.pandas_datetime # noqa # isort: skip # type: ignore[reportUnusedImport]
from pandas._libs.interval import Interval
from pandas._libs.tslibs import (
NaT,
Expand Down
5 changes: 0 additions & 5 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ from pandas._libs.tslibs.nattype cimport c_NaT as NaT
from pandas._libs.tslibs.np_datetime cimport (
NPY_DATETIMEUNIT,
get_unit_from_dtype,
import_pandas_datetime,
)

import_pandas_datetime()


from pandas._libs.tslibs.period cimport is_period_object
from pandas._libs.tslibs.timedeltas cimport _Timedelta
from pandas._libs.tslibs.timestamps cimport _Timestamp
Expand Down
6 changes: 2 additions & 4 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ cdef extern from "numpy/arrayobject.h":
cdef extern from "numpy/ndarrayobject.h":
bint PyArray_CheckScalar(obj) nogil

cdef extern from "pd_parser.h":
int floatify(object, float64_t *result, int *maybe_int) except -1
void PandasParser_IMPORT()

PandasParser_IMPORT
cdef extern from "src/parse_helper.h":
int floatify(object, float64_t *result, int *maybe_int) except -1

from pandas._libs cimport util
from pandas._libs.util cimport (
Expand Down
3 changes: 0 additions & 3 deletions pandas/_libs/missing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ from pandas._libs.tslibs.np_datetime cimport (
get_datetime64_unit,
get_datetime64_value,
get_timedelta64_value,
import_pandas_datetime,
)

import_pandas_datetime()

from pandas._libs.ops_dispatch import maybe_dispatch_ufunc_to_dunder_op

cdef:
Expand Down
73 changes: 20 additions & 53 deletions pandas/_libs/parsers.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ cdef extern from "parser/tokenizer.h":
int64_t skip_first_N_rows
int64_t skipfooter
# pick one, depending on whether the converter requires GIL
double (*double_converter)(const char *, char **,
char, char, char,
int, int *, int *) nogil
float64_t (*double_converter)(const char *, char **,
char, char, char,
int, int *, int *) nogil

# error handling
char *warn_msg
Expand All @@ -249,16 +249,6 @@ cdef extern from "parser/tokenizer.h":
int seen_uint
int seen_null

void COLITER_NEXT(coliter_t, const char *) nogil

cdef extern from "pd_parser.h":
void *new_rd_source(object obj) except NULL

int del_rd_source(void *src)

void* buffer_rd_bytes(void *source, size_t nbytes,
size_t *bytes_read, int *status, const char *encoding_errors)

void uint_state_init(uint_state *self)
int uint64_conflict(uint_state *self)

Expand Down Expand Up @@ -289,49 +279,26 @@ cdef extern from "pd_parser.h":
uint64_t str_to_uint64(uint_state *state, char *p_item, int64_t int_max,
uint64_t uint_max, int *error, char tsep) nogil

double xstrtod(const char *p, char **q, char decimal,
char sci, char tsep, int skip_trailing,
int *error, int *maybe_int) nogil
double precise_xstrtod(const char *p, char **q, char decimal,
char sci, char tsep, int skip_trailing,
int *error, int *maybe_int) nogil
double round_trip(const char *p, char **q, char decimal,
float64_t xstrtod(const char *p, char **q, char decimal,
char sci, char tsep, int skip_trailing,
int *error, int *maybe_int) nogil
float64_t precise_xstrtod(const char *p, char **q, char decimal,
char sci, char tsep, int skip_trailing,
int *error, int *maybe_int) nogil
float64_t round_trip(const char *p, char **q, char decimal,
char sci, char tsep, int skip_trailing,
int *error, int *maybe_int) nogil

int to_boolean(const char *item, uint8_t *val) nogil

void PandasParser_IMPORT()

PandasParser_IMPORT

# When not invoked directly but rather assigned as a function,
# cdef extern'ed declarations seem to leave behind an undefined symbol
cdef double xstrtod_wrapper(const char *p, char **q, char decimal,
char sci, char tsep, int skip_trailing,
int *error, int *maybe_int) nogil:
return xstrtod(p, q, decimal, sci, tsep, skip_trailing, error, maybe_int)


cdef double precise_xstrtod_wrapper(const char *p, char **q, char decimal,
char sci, char tsep, int skip_trailing,
int *error, int *maybe_int) nogil:
return precise_xstrtod(p, q, decimal, sci, tsep, skip_trailing, error, maybe_int)


cdef double round_trip_wrapper(const char *p, char **q, char decimal,
char sci, char tsep, int skip_trailing,
int *error, int *maybe_int) nogil:
return round_trip(p, q, decimal, sci, tsep, skip_trailing, error, maybe_int)

cdef extern from "parser/io.h":
void *new_rd_source(object obj) except NULL

cdef void* buffer_rd_bytes_wrapper(void *source, size_t nbytes,
size_t *bytes_read, int *status,
const char *encoding_errors) noexcept:
return buffer_rd_bytes(source, nbytes, bytes_read, status, encoding_errors)
int del_rd_source(void *src)

cdef int del_rd_source_wrapper(void *src) noexcept:
return del_rd_source(src)
void* buffer_rd_bytes(void *source, size_t nbytes,
size_t *bytes_read, int *status, const char *encoding_errors)


cdef class TextReader:
Expand Down Expand Up @@ -518,11 +485,11 @@ cdef class TextReader:

if float_precision == "round_trip":
# see gh-15140
self.parser.double_converter = round_trip_wrapper
self.parser.double_converter = round_trip
elif float_precision == "legacy":
self.parser.double_converter = xstrtod_wrapper
self.parser.double_converter = xstrtod
elif float_precision == "high" or float_precision is None:
self.parser.double_converter = precise_xstrtod_wrapper
self.parser.double_converter = precise_xstrtod
else:
raise ValueError(f"Unrecognized float_precision option: "
f"{float_precision}")
Expand Down Expand Up @@ -640,8 +607,8 @@ cdef class TextReader:

ptr = new_rd_source(source)
self.parser.source = ptr
self.parser.cb_io = buffer_rd_bytes_wrapper
self.parser.cb_cleanup = del_rd_source_wrapper
self.parser.cb_io = &buffer_rd_bytes
self.parser.cb_cleanup = &del_rd_source

cdef _get_header(self, list prelim_header):
# header is now a list of lists, so field_count should use header[0]
Expand Down
178 changes: 0 additions & 178 deletions pandas/_libs/pd_parser.c

This file was deleted.

Loading