Skip to content

np.setbufsize accepts negative values silently instead of raising an error #29651

@Kairoven

Description

@Kairoven

numpy.setbufsize currently accepts negative values for size, but does nothing silently.

import numpy as np

print("Default bufsize:", np.getbufsize())  # 8192

with np.errstate():
    prev = np.setbufsize(-1024)   # negative size, meaningless
    print("Previous bufsize:", prev)          # 8192
    print("Current bufsize:", np.getbufsize())  # still 8192, unchanged

# automatically restored
print("Restored bufsize:", np.getbufsize())  # 8192

I know that negative buffer sizes have no real meaning. Should this be treated the same as other invalid sizes (e.g., very small values), and raise an error instead of silently doing nothing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: lowValid, but not for immediate attention

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions