Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: Uniform interface for accessing minimum or maximum value of a dtype #27785

Open
@carlosgmartin

Description

@carlosgmartin

Proposed new feature or change:

Mailing list post

Feature request: Add a uniform interface for accessing the minimum or maximum value of a given dtype.

Previously discussed here, here, and here. Currently, doing this requires branching on the type of dtype (boolean, integer, or floating point) and then (for the latter two) calling either iinfo or finfo, respectively. It would be more ergonomic to have a single, uniform interface for accessing this information that is dtype-independent.

Here are the possible interfaces suggested so far:

import numpy as np
dt = np.int32 # example

# As an attribute of the dtype itself:
dt.min
dt.min_value
dt.info().min
dt.info.min

# As a function in numpy.dtypes:
np.dtypes.info(dt).min
np.dtypes.min(dt)
np.dtypes.min_value(dt)

# As a top-level function:
np.min_dtype_value(dt)
np.dtype_info(dt).min
np.dtype_info(dt).min_value

Personally, my current favorite is simply dt.min.

Relevant comment by @mhvk on the mailing list thread:

It would also seem to make sense to consider how the dtype itself can hold/calculate this type of information, since that will be the only way a generic info() function can get information for a user-defined dtype. Indeed, taking that further, might a method or property on the dtype itself be the cleaner interface?

Metadata

Metadata

Assignees

No one assigned

    Labels

    62 - Python APIChanges or additions to the Python API. Mailing list should usually be notified.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions