MCPcopy
hub / github.com/pandas-dev/pandas / read

Method read

pandas/io/parsers/python_parser.py:271–325  ·  view source on GitHub ↗
(
        self, rows: int | None = None
    )

Source from the content-addressed store, hash-verified

269 return reader
270
271 def read(
272 self, rows: int | None = None
273 ) -> tuple[
274 Index | None,
275 Sequence[Hashable] | MultiIndex,
276 Mapping[Hashable, ArrayLike | Series],
277 ]:
278 try:
279 content = self._get_lines(rows)
280 except StopIteration:
281 if self._first_chunk:
282 content = []
283 else:
284 self.close()
285 raise
286
287 # done with first read, next time raise StopIteration
288 self._first_chunk = False
289
290 index: Index | None
291 columns: Sequence[Hashable] = list(self.orig_names)
292 if not content: # pragma: no cover
293 # DataFrame with the right metadata, even though it's length 0
294 # error: Cannot determine type of 'index_col'
295 names = dedup_names(
296 self.orig_names,
297 is_potential_multi_index(
298 self.orig_names,
299 self.index_col,
300 ),
301 )
302 index, columns, col_dict = self._get_empty_meta(
303 names,
304 self.dtype,
305 )
306 conv_columns = self._maybe_make_multi_index_columns(columns, self.col_names)
307 return index, conv_columns, col_dict
308
309 # handle new style for names in index
310 indexnamerow = None
311 if self.has_index_names and sum(
312 int(v == "" or v is None) for v in content[0]
313 ) == len(columns):
314 indexnamerow = content[0]
315 content = content[1:]
316
317 alldata = self._rows_to_cols(content)
318 data, columns = self._exclude_implicit_index(alldata)
319
320 conv_data = self._convert_data(data)
321 conv_data = self._do_date_conversions(columns, conv_data)
322
323 index, result_columns = self._make_index(alldata, columns, indexnamerow)
324
325 return index, result_columns, conv_data
326
327 def _exclude_implicit_index(
328 self,

Callers 1

get_chunkMethod · 0.95

Calls 12

_get_linesMethod · 0.95
_rows_to_colsMethod · 0.95
_convert_dataMethod · 0.95
dedup_namesFunction · 0.90
is_potential_multi_indexFunction · 0.90
sumFunction · 0.85
_get_empty_metaMethod · 0.80
_do_date_conversionsMethod · 0.80
_make_indexMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected