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

[WIP] fix #86c, #37, #39, added support to many numpy functions #704

Closed
wants to merge 18 commits into from

Conversation

impact27
Copy link
Contributor

  • added a asQuantity function to transform an array into a Quantity (a bit like numpy's asarray)
  • Allowed transformation of array of Quantity to Quantity
  • A dimensionless 0 should be compared and added (Remove the distinction between 0 and dimensionless zero)
  • A Quantity is not an ndarray! is has an ndarray. Therefore it should not respond to ['__array_interface__', '__array_struct__' , '__array__', '_data']
  • added __array_ufunc__ to handle numpy function

@impact27
Copy link
Contributor Author

The fail with pandas comes from the fact that pandas can't really test for nan with the new implementation. I am not sure how to fix it.
The relevant code is in pandas/core/dtypes/missing.py

def _isna_new(obj):
    if is_scalar(obj):
        return libmissing.checknull(obj)
    # hack (for now) because MI registers as ndarray
    elif isinstance(obj, ABCMultiIndex):
        raise NotImplementedError("isna is not defined for MultiIndex")
    elif isinstance(obj, (ABCSeries, np.ndarray, ABCIndexClass,
                          ABCExtensionArray)):
        return _isna_ndarraylike(obj)
    elif isinstance(obj, ABCGeneric):
        return obj._constructor(obj._data.isna(func=isna))
    elif isinstance(obj, list):
        return _isna_ndarraylike(np.asarray(obj, dtype=object))
    elif hasattr(obj, '__array__'):
        return _isna_ndarraylike(np.asarray(obj))
    else:
        return obj is None

Also, older versions of numpy fails because they want Quantity to be an array. The problem is that if Quantity gives an array representation, the units are lost. So these changes can only be applied to newer versions of numpy. Maybe the solution is to only return the __array_ methods if the version of numpy is below some number?

@impact27
Copy link
Contributor Author

impact27 commented Oct 10, 2018

fix #714, kind of fix #484

@hgrecco
Copy link
Owner

hgrecco commented Dec 28, 2019

This has been superseed by #905 and related

@hgrecco hgrecco closed this Dec 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants