Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

DEP: Deprecate constructing dtypes from any object having a .dtype attribute #25306

Copy link
Copy link
Open
@timhoffm

Description

@timhoffm
Issue body actions

Proposed new feature or change:

I suggest to deprecate this feature. This is essentially already alluded in "we could consider deprecating even more" in #13578 (comment).

It seems too permissive (allowing sloppy user code) and complicates NumPy code (e.g. #13003). Users should instead dereference the .dtype attribute explicitly ("explicit is better than implicit"), e.g.

np.array(data, dtype=obj.dtype)
# instead of
np.array(data, dtype=obj)

Also, the current documentation is not exactly correct. It claims

Any type object with a .dtype attribute

but NumPy explicitly disallows this for ndarrays - for good reason, because np.array(data, dtype=other_array) would be semantically sloppy.

OTOH, I can for example do this with a pandas.Series (np.array(data, dtype=series)). IMHO this should not work for pandas.Series or other objects. An additional unwanted side effect is that one can have quite strange comparions due to dtypes comparing True to valid data type specifications

>>> np.dtype('int64') == pd.Series([1, 2])
True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.