Skip to content

BUG: numpy.loadtxt reads only 50000 lines when skip_rows >= max_rows #28315

@l09rin

Description

@l09rin

Describe the issue:

As in the title, probably related to the closed issue #26754 .

Reproduce the code example:

import numpy as np
import os
from tempfile import NamedTemporaryFile, mkstemp

file_length = 400000
data = np.arange(1,file_length+1).astype(str) + " a 0.5 1"
fd, fname = mkstemp()
os.close(fd)
with open(fname, "w") as fh:
    fh.write("\n".join(data))
res = np.loadtxt(fname, dtype = 'str', delimiter=" ", skiprows=200000, max_rows=100000)
print(len(res), len(res) == 100000)  # 50000 False

Error message:

Python and NumPy Versions:

2.2.2
3.11.0rc1 (main, Aug 12 2022, 10:02:14) [GCC 11.2.0]

Runtime Environment:

No response

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions