Read rows from self.f, skipping as specified. We distinguish buffer_rows (the first <= infer_nrows lines) from the rows returned to detect_colspecs because it's simpler to leave the other locations with skiprows logic alone than to modify them to dea
(self, infer_nrows: int, skiprows: set[int] | None = None)
| 1418 | ) |
| 1419 | |
| 1420 | def get_rows(self, infer_nrows: int, skiprows: set[int] | None = None) -> list[str]: |
| 1421 | """ |
| 1422 | Read rows from self.f, skipping as specified. |
| 1423 | |
| 1424 | We distinguish buffer_rows (the first <= infer_nrows |
| 1425 | lines) from the rows returned to detect_colspecs |
| 1426 | because it's simpler to leave the other locations |
| 1427 | with skiprows logic alone than to modify them to |
| 1428 | deal with the fact we skipped some rows here as |
| 1429 | well. |
| 1430 | |
| 1431 | Parameters |
| 1432 | ---------- |
| 1433 | infer_nrows : int |
| 1434 | Number of rows to read from self.f, not counting |
| 1435 | rows that are skipped. |
| 1436 | skiprows: set, optional |
| 1437 | Indices of rows to skip. |
| 1438 | |
| 1439 | Returns |
| 1440 | ------- |
| 1441 | detect_rows : list of str |
| 1442 | A list containing the rows to read. |
| 1443 | |
| 1444 | """ |
| 1445 | if skiprows is None: |
| 1446 | skiprows = set() |
| 1447 | buffer_rows = [] |
| 1448 | detect_rows = [] |
| 1449 | for i, row in enumerate(self.f): |
| 1450 | if i not in skiprows: |
| 1451 | detect_rows.append(row) |
| 1452 | buffer_rows.append(row) |
| 1453 | if len(detect_rows) >= infer_nrows: |
| 1454 | break |
| 1455 | self.buffer = iter(buffer_rows) |
| 1456 | return detect_rows |
| 1457 | |
| 1458 | def detect_colspecs( |
| 1459 | self, infer_nrows: int = 100, skiprows: set[int] | None = None |