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

Method read

pandas/io/parsers/c_parser_wrapper.py:203–325  ·  view source on GitHub ↗
(
        self,
        nrows: int | None = None,
    )

Source from the content-addressed store, hash-verified

201 self._reader.set_noconvert(col)
202
203 def read(
204 self,
205 nrows: int | None = None,
206 ) -> tuple[
207 Index | MultiIndex | None,
208 Sequence[Hashable] | MultiIndex,
209 Mapping[Hashable, AnyArrayLike],
210 ]:
211 index: Index | MultiIndex | None
212 column_names: Sequence[Hashable] | MultiIndex
213 try:
214 if self.low_memory:
215 chunks = self._reader.read_low_memory(nrows)
216 # destructive to chunks
217 data = _concatenate_chunks(chunks, self.names)
218 else:
219 data = self._reader.read(nrows)
220 except StopIteration:
221 if self._first_chunk:
222 self._first_chunk = False
223 # assert for mypy, orig_names is List or None, None would error in
224 # list(...) in dedup_names
225 assert self.orig_names is not None
226 names = dedup_names(
227 self.orig_names,
228 is_potential_multi_index(self.orig_names, self.index_col),
229 )
230 index, columns, col_dict = self._get_empty_meta(
231 names,
232 dtype=self.dtype,
233 )
234 # error: Incompatible types in assignment (expression has type
235 # "list[Hashable] | MultiIndex", variable has type "list[Hashable]")
236 columns = self._maybe_make_multi_index_columns( # type: ignore[assignment]
237 columns, self.col_names
238 )
239
240 columns = _filter_usecols(self.usecols, columns)
241 columns_set = set(columns)
242
243 col_dict = {k: v for k, v in col_dict.items() if k in columns_set}
244
245 return index, columns, col_dict
246
247 else:
248 self.close()
249 raise
250
251 # Done with first read, next time raise StopIteration
252 self._first_chunk = False
253
254 names = self.names
255
256 if self._reader.leading_cols:
257 # implicit index, no index names
258 arrays = []
259
260 if self.index_col and self._reader.leading_cols != len(self.index_col):

Callers

nothing calls this directly

Calls 15

closeMethod · 0.95
dedup_namesFunction · 0.90
is_potential_multi_indexFunction · 0.90
date_converterFunction · 0.90
_concatenate_chunksFunction · 0.85
_filter_usecolsFunction · 0.85
ParserErrorClass · 0.85
_get_empty_metaMethod · 0.80
_should_parse_datesMethod · 0.80
_do_date_conversionsMethod · 0.80

Tested by

no test coverage detected