MCPcopy Create free account
hub / github.com/numpy/numpy / _load_from_filelike

Function _load_from_filelike

numpy/core/src/multiarray/textreading/readtext.c:181–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179
180
181NPY_NO_EXPORT PyObject *
182_load_from_filelike(PyObject *NPY_UNUSED(mod),
183 PyObject *const *args, Py_ssize_t len_args, PyObject *kwnames)
184{
185 PyObject *file;
186 Py_ssize_t skiplines = 0;
187 Py_ssize_t max_rows = -1;
188 PyObject *usecols_obj = Py_None;
189 PyObject *converters = Py_None;
190
191 PyObject *dtype = Py_None;
192 PyObject *encoding_obj = Py_None;
193 const char *encoding = NULL;
194
195 parser_config pc = {
196 .delimiter = ',',
197 .quote = '"',
198 .comment = '#',
199 .ignore_leading_whitespace = false,
200 .delimiter_is_whitespace = false,
201 .imaginary_unit = 'j',
202 .python_byte_converters = false,
203 .c_byte_converters = false,
204 .gave_int_via_float_warning = false,
205 };
206 bool filelike = true;
207
208 PyObject *arr = NULL;
209
210 NPY_PREPARE_ARGPARSER;
211 if (npy_parse_arguments("_load_from_filelike", args, len_args, kwnames,
212 "file", NULL, &file,
213 "|delimiter", &parse_control_character, &pc.delimiter,
214 "|comment", &parse_control_character, &pc.comment,
215 "|quote", &parse_control_character, &pc.quote,
216 "|imaginary_unit", &parse_control_character, &pc.imaginary_unit,
217 "|usecols", NULL, &usecols_obj,
218 "|skiplines", &PyArray_IntpFromPyIntConverter, &skiplines,
219 "|max_rows", &PyArray_IntpFromPyIntConverter, &max_rows,
220 "|converters", NULL, &converters,
221 "|dtype", NULL, &dtype,
222 "|encoding", NULL, &encoding_obj,
223 "|filelike", &PyArray_BoolConverter, &filelike,
224 "|byte_converters", &PyArray_BoolConverter, &pc.python_byte_converters,
225 "|c_byte_converters", PyArray_BoolConverter, &pc.c_byte_converters,
226 NULL, NULL, NULL) < 0) {
227 return NULL;
228 }
229
230 /* Reject matching control characters, they just rarely make sense anyway */
231 if (error_if_matching_control_characters(
232 pc.delimiter, pc.quote, pc.comment) < 0) {
233 return NULL;
234 }
235
236 if (pc.delimiter == (Py_UCS4)-1) {
237 pc.delimiter_is_whitespace = true;
238 /* Ignore leading whitespace to match `string.split(None)` */

Callers 1

_readFunction · 0.85

Calls 4

stream_python_fileFunction · 0.85
stream_python_iterableFunction · 0.85
_readtext_from_streamFunction · 0.85

Tested by

no test coverage detected