-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: Accept callable for skiprows in read_csv #15059
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,6 +178,7 @@ cdef extern from "parser/tokenizer.h": | |
int header_end # header row end | ||
|
||
void *skipset | ||
PyObject *skipfunc | ||
int64_t skip_first_N_rows | ||
int skipfooter | ||
double (*converter)(const char *, char **, char, char, char, int) nogil | ||
|
@@ -606,9 +607,11 @@ cdef class TextReader: | |
cdef _make_skiprow_set(self): | ||
if isinstance(self.skiprows, (int, np.integer)): | ||
parser_set_skipfirstnrows(self.parser, self.skiprows) | ||
else: | ||
elif not callable(self.skiprows): | ||
for i in self.skiprows: | ||
parser_add_skiprow(self.parser, i) | ||
else: | ||
self.parser.skipfunc = <PyObject *> self.skiprows | ||
|
||
cdef _setup_parser_source(self, source): | ||
cdef: | ||
|
@@ -2115,18 +2118,33 @@ cdef kh_float64_t* kset_float64_from_list(values) except NULL: | |
cdef raise_parser_error(object base, parser_t *parser): | ||
cdef: | ||
object old_exc | ||
object exc_type | ||
PyObject *type | ||
PyObject *value | ||
PyObject *traceback | ||
|
||
if PyErr_Occurred(): | ||
PyErr_Fetch(&type, &value, &traceback); | ||
Py_XDECREF(type) | ||
PyErr_Fetch(&type, &value, &traceback) | ||
Py_XDECREF(traceback) | ||
|
||
if value != NULL: | ||
old_exc = <object> value | ||
Py_XDECREF(value) | ||
raise old_exc | ||
|
||
# PyErr_Fetch only returned the error message in *value, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why was this not necessary before? this seems like lots of hoop jumping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think because we got lucky. This should have been caught before and processed accordingly. It's annoying, but that's what happens unfortunately when the Python C API can't promise you anything. |
||
# so the Exception class must be extracted from *type. | ||
if isinstance(old_exc, compat.string_types): | ||
if type != NULL: | ||
exc_type = <object> type | ||
else: | ||
exc_type = ParserError | ||
|
||
Py_XDECREF(type) | ||
raise exc_type(old_exc) | ||
else: | ||
Py_XDECREF(type) | ||
raise old_exc | ||
|
||
message = '%s. C error: ' % base | ||
if parser.error_msg != NULL: | ||
if PY3: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add tests with bad functions (raises and returns non-bool) - in particular want to make sure error propagates from c-engine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Done.