Skip to content

[MNT]: use to_numpy more #21036

Closed
Closed

Description

@jklymak

Summary

Both pandas and xarray now have a to_numpy method on their data objects. We only use to_numpy once in cbook._reshape_2D, and instead usually check .values. We probably should be using to_numpy more if that is indeed the new idiom for converting?

Ping @shoyer for xarray and @TomAugspurger for pandas, though please feel free to redirect as appropriate, you are being picked upon because you've interacted with us before 😉.

One thing I note for to_numpy and dates is that it does not seem to convert to numpy datetime64 or timedelta64 for either package - it'd be nice if they did!

Activity

  1. TomAugspurger commented on Sep 10, 2021

    @TomAugspurger
    Contributor

    In general, I recommend using to_numpy() or np.asarray rather than .values. Then you know for certain that you have an ndarray.

    One thing I note for to_numpy and dates is that it does not seem to convert to numpy datetime64 or timedelta64 for either package - it'd be nice if they did!

    Just confirming, you mean dates (and not datetimes)? In pandas, those will be stored as object dtype, and I don't think to_numpy() is the right spot to do type inference or conversion.

  2. jklymak commented on Sep 10, 2021

    @jklymak
    MemberAuthor

    Ok, we definitely use np.asarray however I'll admit my ignorance as to the difference with to_numpy.

  3. TomAugspurger commented on Sep 11, 2021

    @TomAugspurger
    Contributor

    IIRC there were some differences (maybe datetimes with timezones silently cast to UTC in asarray?) but that was deprecated and fixed.

    So the main reason to use to_numpy() now comes from control over na_value, and perhaps copy.

  4. github-actions commented on Nov 3, 2025

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  5. timhoffm commented on Nov 3, 2025

    @timhoffm
    Member

    On a higher level, this is tracked in #22645. On the technical side, we should orient towards the array API standard #22645 (comment).

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions