- Difficulty level: easy
- Time need to lean: 10 minutes or less
After installing iRuby
by following instructions from iRuby Kernel homepage, you will need to install daru
and NMatrix
with command:
gem install daru nmatrix
Basic data types recognised in Ruby are similar with Python's data types and there is a one-to-one correspondence for these types.
The convertion of datatype from SoS to Ruby (e.g. %get
from Ruby) is as followings:
Python | condition | Ruby |
---|---|---|
None |
nil |
|
boolean |
TrueClass or FalseClass |
|
integer |
Integer |
|
float |
Float |
|
complex |
Complex |
|
str |
String |
|
Sequence (list , tuple , ...) |
Array |
|
set |
Set |
|
dict |
Hash |
|
range |
Range |
|
numpy.ndarray |
Array |
|
numpy.matrix |
NMatrix |
|
pandas.Series |
Hash |
|
pandas.DataFrame |
Daru::DataFrame |
Python objects in other datatypes are transferred as string "Unsupported datatype"
. Please let us know if there is a natural corresponding data type in Ruby to convert this data type.
Conversion of datatypes from Ruby to SoS (%get var --from Ruby
from SoS) follows the following rules:
Ruby | condition | Python |
---|---|---|
nil |
None |
|
Float::NAN |
numpy.nan |
|
TrueClass or FalseClass |
boolean |
|
Integer |
integer |
|
String |
str |
|
Complex |
complex |
|
Float |
float |
|
Array |
numpy.ndarray |
|
Range |
range |
|
Set |
set |
|
Hash |
dict |
|
NMatrix |
numpy.matrix |
|
Array |
numpy.ndarray |
|
Daru::DataFrame |
pandas.DataFrame |
Ruby objects in other datatypes are transferred as string "Unsupported datatype"
.
For example, the scalar data is converted from SoS to Ruby as follows:
Ruby supports DataFrame from its daru (Data Analysis in RUby) library so you will need to install this library before using the Ruby kernel. For example, a R dataframe is transfered as Daru::DataFrame to Ruby.
Also, we choose NMatrix library in Ruby becuase its fast performance. Same as daru (Data Analysis in RUby), you will need to install nmatrix library before using the Ruby kernel.