Skip to content

Numpy v1 compatibility broken on main with DimArray #727

Description

@JamesWrigley

Affects: PythonCall

Describe the bug
ArrayValue.__array__() now supports the copy argument and defaults to copy=None, but this is not supported on numpy v1 and breaks when using a DimArray from DimensionalData.jl:

# Works
@pyeval (x=rand(10), np) => "np.asarray(x)"

# Fails
@pyeval (x=rand(X(10)), np) => "np.asarray(x)"
Python: ValueError: NoneType copy mode not allowed.
Python stacktrace:
 [1] __array__
   @ /path/to/julia-depot/packages/PythonCall/syXxf/src/JlWrap/array.jl:371
 [2] <module>
   @ In[44]:1:1

Not sure why it only breaks with DimArray but works with Array.

Your system
Please provide detailed information about your system:

  • Linux
  • Julia 1.12.2, PythonCall main, Python 3.11.13, Numpy 1.26.4.

Activity

  1. cjdoris commented on Dec 1, 2025

    @cjdoris
    Member

    Thanks. I think the fix is to call np.asarray instead of np.array when copy=None because np.array(x, copy=None) is not supported in numpy v1.

  2. JamesWrigley commented on Dec 3, 2025

    @JamesWrigley
    ContributorAuthor

    Hmm, but that doesn't explain why it works with Array and not DimArray 🤔 I think something else is happening.

  3. cjdoris commented on Dec 6, 2025

    @cjdoris
    Member

    My guess is that Base.unsafe_convert(::Type{Ptr{T}}, ::DimArray) is not defined, which is required to be wrappable as a python array, since this is how we get a pointer to the underlying data.

    In this case we fall back to converting the array to an Array, and perhaps the above issue only arises in this branch?

  4. JamesWrigley commented on Dec 6, 2025

    @JamesWrigley
    ContributorAuthor

    Is that a new requirement? Because it did work in the last stable release.

  5. cjdoris commented on Dec 6, 2025

    @cjdoris
    Member

    No it's not new. Can you give an MWE showing it working and not working?

  6. JamesWrigley commented on Jan 16, 2026

    @JamesWrigley
    ContributorAuthor

    Actually no sorry, I think I was mistaken 😕

  7. JamesWrigley commented on Jan 16, 2026

    @JamesWrigley
    ContributorAuthor

    My guess is that Base.unsafe_convert(::Type{Ptr{T}}, ::DimArray) is not defined, which is required to be wrappable as a python array, since this is how we get a pointer to the underlying data.

    Yep you're quite right, I'll close this then since it's not a PythonCall issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions