question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Java arrays passed to python script can't be passed to pandas.DataFrame

See original GitHub issue

I have a double array in java. When i print the array it shows like: [6.390933837890625, 6.412708740234375, 6.383675537109375, 6.398192138671875, 6.40907958984375, 6.40907958984375, 6.416337890625, 6.4054504394531255, 6.40907958984375.....]

I pass it as arg to a python script func:

Python py = Python.getInstance();
PyObject pyObject=py.getModule("test");
pyObject.callAttr("showArr",darr);

Where my test.py is:

def showArr(arr):
	print(arr)

in python o/p it shows: jarray('D')([6.390933837890625, 6.412708740234375, 6.383675537109375, 6.398192138671875, .......])

Because of this am not being able to call pandas.DataFrame(arr) When i print a simple array in python it prints fine:

>>> arr=[1,2,3]
>>> print(arr)
[1, 2, 3]

Why does this jarray('D') gets prepended when i pass the double array to the py script?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mhsmithcommented, Jun 5, 2020

The jarray is being printed to indicate the object type, just like a Numpy array is printed as array(...).

I assume the error you got when passing the array to pandas.DataFrame was TypeError: __getbuffer__ is not implemented for double[]. This will be fixed in the next version of Chaquopy.

Meanwhile, you can work around it by writing pandas.DataFrame(list(arr)).

0reactions
mhsmithcommented, Sep 22, 2021

This issue is fixed in Chaquopy 10.0.1, except for the 1-dimensional case mentioned in the previous comment.

To upgrade, edit your app’s top-level build.gradle file and change the version number of com.chaquo.python:gradle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python pandas dataframe, is it pass-by-value ... - Stack Overflow
The short answer is, Python always does pass-by-value, but every Python variable is actually a pointer to some object, so sometimes it looks ......
Read more >
25. Accessing and Changing values of DataFrames
This chapter of our Pandas and Python tutorial will show various ways to access and change selectively values in Pandas DataFrames and Series....
Read more >
Different ways to create Pandas Dataframe - GeeksforGeeks
Method #8: Creating DataFrame from Dictionary of series. To create DataFrame from Dict of series, dictionary can be passed to form a DataFrame....
Read more >
Python Pandas Series - javatpoint
Before creating a Series, firstly, we have to import the numpy module and then use array() function in the program. If the data...
Read more >
Load a pandas DataFrame | TensorFlow Core
Read data using pandas; A DataFrame as an array ... When you pass the DataFrame as the x argument to Model.fit , Keras...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found