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

Method _record_count

pandas/io/sas/sas_xport.py:386–422  ·  view source on GitHub ↗

Get number of records in file. This is maybe suboptimal because we have to seek to the end of the file. Side effect: returns file position to record_start.

(self)

Source from the content-addressed store, hash-verified

384 return self.read(nrows=self._chunksize or 1)
385
386 def _record_count(self) -> int:
387 """
388 Get number of records in file.
389
390 This is maybe suboptimal because we have to seek to the end of
391 the file.
392
393 Side effect: returns file position to record_start.
394 """
395 self.filepath_or_buffer.seek(0, 2)
396 total_records_length = self.filepath_or_buffer.tell() - self.record_start
397
398 if total_records_length % 80 != 0:
399 warnings.warn(
400 "xport file may be corrupted.",
401 stacklevel=find_stack_level(),
402 )
403
404 if self.record_length > 80:
405 self.filepath_or_buffer.seek(self.record_start)
406 return total_records_length // self.record_length
407
408 self.filepath_or_buffer.seek(-80, 2)
409 last_card_bytes = self.filepath_or_buffer.read(80)
410 last_card = np.frombuffer(last_card_bytes, dtype=np.uint64)
411
412 # 8 byte blank
413 ix = np.flatnonzero(last_card == 2314885530818453536)
414
415 if len(ix) == 0:
416 tail_pad = 0
417 else:
418 tail_pad = 8 * len(ix)
419
420 self.filepath_or_buffer.seek(self.record_start)
421
422 return (total_records_length - tail_pad) // self.record_length
423
424 def get_chunk(self, size: int | None = None) -> pd.DataFrame:
425 """

Callers 1

_read_headerMethod · 0.95

Calls 4

find_stack_levelFunction · 0.90
seekMethod · 0.45
tellMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected