Skip to content

Conversation

@xhochy
Copy link
Member

@xhochy xhochy commented Mar 4, 2018

Usage with Arrow Java vectors:

import jpype
import numpy as np
import pyarrow as pa
import sys

# Start JVM with Arrow and all of its dependencies.
jpype.startJVM(getDefaultJVMPath(), "-Djava.class.path=arrow-tools-0.9.0-SNAPSHOT-jar-with-dependencies.jar")

# Create vector
ra = jpype.JPackage("org").apache.arrow.memory.RootAllocator(sys.maxsize)
uint1 = jpype.JPackage("org").apache.arrow.vector.UInt1Vector("int", ra)
uint1.allocateNew(128)
for i in range(128):
    uint1.setSafe(i, i)
uint1.setValueCount(128)

# Access it in Python
addr = uint1.getDataBuffer().unwrap().memoryAddress()
size = uint1.getDataBuffer().unwrap().capacity()
fb = pa.ForeignBuffer(addr, size, n)
np.asarray(fb)

Output (as expected):

array([  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,
        13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,
        26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,
        39,  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51,
        52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,
        65,  66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,
        78,  79,  80,  81,  82,  83,  84,  85,  86,  87,  88,  89,  90,
        91,  92,  93,  94,  95,  96,  97,  98,  99, 100, 101, 102, 103,
       104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
       117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127], dtype=int8)

@xhochy xhochy force-pushed the ARROW-2252 branch 2 times, most recently from 0ffffd4 to 86a9a6d Compare March 4, 2018 16:52
Copy link
Member

@wesm wesm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. When we document this, we should perhaps indicate that the API is experimental

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