jupyter-incubator / sparkmagic

Jupyter magics and kernels for working with remote Spark clusters
Other
1.33k stars 447 forks source link

'int' object has no attribute 'toJSON' #532

Open ashkan-leo opened 5 years ago

ashkan-leo commented 5 years ago

I am running the following:

%spark -o num_records
some_data_frame.select(keys).distinct().count()

And I get the following exception:

An error was encountered:
'int' object has no attribute 'toJSON'
Traceback (most recent call last):
AttributeError: 'int' object has no attribute 'toJSON'
BertrandBrelier commented 4 years ago

To whom it may concern,

I am experiencing the same issue trying to share remote variables (I tried a pandas dataframe, an int and a string) with my local notebook.

An error was encountered: 'str' object has no attribute 'toJSON' Traceback (most recent call last): AttributeError: 'str' object has no attribute 'toJSON'

I am using sparkmagic-0.15.0 with python3 ("spark.pyspark.python": "python3").

Any suggestions ?

Thanks for your help,

oztalha commented 2 years ago

Not an ideal solution but whatever you want to pass you can convert it to a Spark Dataframe first. If it is a primitive data type like an integer for example:

%spark -o i
i = spark.createDataFrame([[1]])

then read on your local:

%local
i.iloc[0,0]