Numpy: Np.finfo Does Not Fail As One Would Expect
I am using numpy.iinfo and np.finfo to test whether a given type or value is corresponds to an integer or a float. There is a weird behaviour when dealing with None.
The following fails, as expected:
np.iinfo(None)
Nevertheless
np.finfo(None)
does not, as I would expect. Is that a bug? IMHO when type(None) returns NoneType, then np.finfo should fail as np.iinfo does.
Answer
On a purely technical level we can explain what you are seeing by looking at the source
The relevant snippet would be
@set_module('numpy')
class finfo(object):
<--snip-->
def __new__(cls, dtype):
try:
dtype = numeric.dtype(dtype)
except TypeError:
# In case a float instance was given
dtype = numeric.dtype(type(dtype))
The behavior you see is a consequence of np.dtype(None)
evaluating to dtype('float64')
, which in itself doesn't feel 100% natural to me. Others (including devs) seem to agree. For example
Oh, well, we could probably deprecate dtype(None), which seems pretty useless, but I don't know if it's worth the bother...
Based on this discussion and from the code above the way None
is treated does indeed look a bit unintended, but that is just my educated guess.
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module