Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEP: Formally deprecate np.typeDict #17586

Merged
merged 7 commits into from Mar 30, 2021
Merged

DEP: Formally deprecate np.typeDict #17586

merged 7 commits into from Mar 30, 2021

Conversation

BvB93
Copy link
Member

@BvB93 BvB93 commented Oct 19, 2020

Closes #17585.

The np.typeDict dictionary is a deprecated alias for np.sctypeDict and has been so for over 14 years (6689502).

This PR formally marks it a such, the module-level __getattr__ now issuing a deprecation warning whenever getting np.typeDict.

@eric-wieser
Copy link
Member

My main concern here is that maybe we should be doing the deprecation in the other direction... How many callers of sctypeDict are there? In my opinion, sctypeDict is the worse name, as:

  • sc is a weird prefix that we've moved away from
  • It mixes lowercase with camelCase into something that is hard to get right.

@BvB93
Copy link
Member Author

BvB93 commented Oct 19, 2020

My main concern here is that maybe we should be doing the deprecation in the other direction... How many callers of sctypeDict are there? In my opinion, sctypeDict is the worse name, as:

Roughly speaking there about twice as many callers of typeDict compared to its sctypeDict alias.
In the grant scheme of things neither of them seem to be used a lot.

  • sc is a weird prefix that we've moved away from
  • It mixes lowercase with camelCase into something that is hard to get right.

Switching the deprecation around would fix the first issue; though typeDict very much suffers from the second issue as well.

Personally I don't have any particularly strong opinion about which on to keep and which one to discard.

numpy/__init__.py Outdated Show resolved Hide resolved
@eric-wieser
Copy link
Member

I suppose the other option is we just deprecate both. np.typeDict(x) is the same as np.dtype(x).type, and set(np.typeDict.values()) is {np.dtype(c).type for c in np.typecodes['All']}

@BvB93
Copy link
Member Author

BvB93 commented Oct 19, 2020

The only department where sctypeDict is somewhat unique is its keys, as they contain all (?) valid names for fixed-size dtypes.

@mattip
Copy link
Member

mattip commented Oct 29, 2020

they contain all (?) valid names for fixed-size dtypes

Do we have a canonical way to get this information without these dictionaries?

@BvB93
Copy link
Member Author

BvB93 commented Oct 29, 2020

Do we have a canonical way to get this information without these dictionaries?

Not as far as I'm aware, no.
The machinery for constructing all the aliases in sctypeDict is located in numpy/core/_type_aliases.py,
which consists nearly exclusivelly of lots of private functions.

@eric-wieser
Copy link
Member

eric-wieser commented Oct 29, 2020

as they contain all (?) valid names for fixed-size dtypes.

Is there a valid reason for a user to actually want this? This is the type of trap that leads to users iterating over these names when they should just be iterating over the types themselves.

@BvB93
Copy link
Member Author

BvB93 commented Oct 29, 2020

Is there a valid reason for a user to actually want this?

The main reason I can think of is for the purpose of documentation, as the current arrays.scalars docs
fail to mention kind + itemsize based aliases.
Admitetly this is not an argument for keeping sctypeDict, it's one for expanding the documentation.

@eric-wieser
Copy link
Member

Right - it's useful internally for generating documentation if we want to go down that route, but any downstream project using it probably is doing the wrong thing.

@rgommers
Copy link
Member

rgommers commented Jan 2, 2021

In the docs sctypeDict is used 3 times, only once outside of release notes (in this data types section though, which should be authoritative). typeDict is ony used 1 time, in the 1.20.0 release notes.

Right - it's useful internally for generating documentation if we want to go down that route, but any downstream project using it probably is doing the wrong thing.

Agreed. I checked scipy, pandas, scikit-learn, scikit-image, statsmodels and astropy, and there's only two usages in SciPy that look correct but weird.

Given that sctypeDict is the one documented use, I think deprecating typeDict now is right. Deprecating sctypeDict would be useful too, but I'd rather we first clean up the documentation and remove usage in SciPy first, give a heads up to others, and do it in 1.22 or 1.23.

@charris
Copy link
Member

charris commented Jan 15, 2021

@BvB93 needs a rebase.

Bas van Beek and others added 7 commits January 16, 2021 02:22
`typeDict` is a deprecated alias for `sctypeDict` and has been so for >= 14 years (numpy@6689502)
See numpy#17586 (comment)

Co-Authored-By: Eric Wieser <425260+eric-wieser@users.noreply.github.com>
* Add a deprecation comment to `numpy/__init__.py`
* Replace a `getattr()` operation with `core.numerictypes.typeDict` 
* Remove a redundant call to `np.sctypeDict`

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@BvB93
Copy link
Member Author

BvB93 commented Jan 16, 2021

Deprecating sctypeDict would be useful too, but I'd rather we first clean up the documentation and remove usage in SciPy first, give a heads up to others, and do it in 1.22 or 1.23.

@rgommers do you feel it would be worthwhile to add a comment in the release note discouraging the use of sctypeDict?

@rgommers
Copy link
Member

A release note sounds like a good idea, as context with this PR. I'm not sure many people read it though; adding that note to https://numpy.org/devdocs/reference/arrays.dtypes.html is probably more effective long-term.

@charris
Copy link
Member

charris commented Jan 25, 2021

This looks ready to go. Comments?

Base automatically changed from master to main March 4, 2021 02:05
@charris charris merged commit ed5abf1 into numpy:main Mar 30, 2021
@charris
Copy link
Member

charris commented Mar 30, 2021

Thanks Bas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DEP: Finalize the deprecation of np.typeDict?
5 participants