red-arrow-pycall 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf65599f0a91aa12e9f93971e981e01b0e83807b
4
- data.tar.gz: 8c9c6cd4a9d052560a85f9e03334cfcc97895e35
3
+ metadata.gz: f44174f03927e0a2c9c00306703c6d371787c1ff
4
+ data.tar.gz: 112085a608bd1fdc3ac523d73f4bb67eefae9f78
5
5
  SHA512:
6
- metadata.gz: cefa69198ad06b139bf67c82459335ca2f6774f75e09d3776c404ca8c94a18700a8d1d5f82361a445e10ea0ad90f01cf15a548c0d5453b4d5484911e95059f4d
7
- data.tar.gz: a541e339f38555aa5300cf144800e509ceca9be610bbc1fc01cf5f3bb1fb7586b363487e4c7805fdae5dc543be725975a66b1d5c29fe96d29a92283b987c8cac
6
+ metadata.gz: 535bb8bb7b4bee42750dee53e4417b74f6503bbb8f22d205f8bcb01e1c4dfb5547f5fce0d61cf08a30c2341b781eedcc68b381cbdc83ec625e28a3af9e6e4683
7
+ data.tar.gz: 2ef2a6bfff37eeccdafb446eb70e666c73bb01e85a3d7ccd7bb60e36bdd23a0a86953a8df0c2c0f54c2a4b403f1cb4965bd86bb9f47062e0d740bf4d82cf27e8
@@ -1,5 +1,25 @@
1
1
  # News
2
2
 
3
+ ## 0.0.4 - 2018-03-07
4
+
5
+ ### Improvements
6
+
7
+ * Added PyCall 1.1.0 support.
8
+
9
+ ## 0.0.3 - 2017-07-13
10
+
11
+ ### Improvements
12
+
13
+ * Supported `sizeof(void *) > sizeof(long)` platform such as Windows
14
+ x64.
15
+ [GitHub#1][Patch by Kenta Murata]
16
+
17
+ * Added `#to_ruby`.
18
+
19
+ ### Thanks
20
+
21
+ * Kenta Murata
22
+
3
23
  ## 0.0.2 - 2017-07-08
4
24
 
5
25
  ### Fixes
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2017 Kouhei Sutou <kou@clear-code.com>
2
+ * Copyright 2017-2018 Kouhei Sutou <kou@clear-code.com>
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -20,87 +20,215 @@
20
20
 
21
21
  #include <arrow/python/pyarrow.h>
22
22
 
23
- extern "C" void Init_arrow_pycall(void);
23
+ #include <pycall.h>
24
+
25
+ namespace {
26
+ inline VALUE to_ruby(PyObject *py_object) {
27
+ return pycall_pyobject_to_ruby(py_object);
28
+ }
29
+
30
+ inline PyObject *to_python(VALUE rb_object) {
31
+ return pycall_pyobject_wrapper_get_pyobj_ptr(rb_object);
32
+ }
33
+ }
24
34
 
25
35
  static VALUE
26
- rb_arrow_buffer_to_python_object_pointer(VALUE self)
36
+ rb_arrow_buffer_to_python(VALUE self)
27
37
  {
28
38
  auto buffer = GARROW_BUFFER(RVAL2GOBJ(self));
29
39
  auto arrow_buffer = garrow_buffer_get_raw(buffer);
30
40
  auto py_buffer = arrow::py::wrap_buffer(arrow_buffer);
31
- return LONG2NUM((long)(py_buffer));
41
+ return to_ruby(py_buffer);
42
+ }
43
+
44
+ static VALUE
45
+ rb_pycall_arrow_buffer_to_ruby(VALUE self)
46
+ {
47
+ auto py_buffer = to_python(self);
48
+ std::shared_ptr<arrow::Buffer> arrow_buffer;
49
+ auto status = arrow::py::unwrap_buffer(py_buffer, &arrow_buffer);
50
+ GError *error = NULL;
51
+ if (!garrow_error_check(&error, status, "[pyarrow][buffer][to-ruby]"))
52
+ RG_RAISE_ERROR(error);
53
+ auto garrow_buffer = garrow_buffer_new_raw(&arrow_buffer);
54
+ return GOBJ2RVAL(garrow_buffer);
32
55
  }
33
56
 
34
57
  static VALUE
35
- rb_arrow_data_type_to_python_object_pointer(VALUE self)
58
+ rb_arrow_data_type_to_python(VALUE self)
36
59
  {
37
60
  auto data_type = GARROW_DATA_TYPE(RVAL2GOBJ(self));
38
61
  auto arrow_data_type = garrow_data_type_get_raw(data_type);
39
62
  auto py_data_type = arrow::py::wrap_data_type(arrow_data_type);
40
- return LONG2NUM((long)(py_data_type));
63
+ return to_ruby(py_data_type);
41
64
  }
42
65
 
43
66
  static VALUE
44
- rb_arrow_field_to_python_object_pointer(VALUE self)
67
+ rb_pycall_arrow_data_type_to_ruby(VALUE self)
68
+ {
69
+ auto py_data_type = to_python(self);
70
+ std::shared_ptr<arrow::DataType> arrow_data_type;
71
+ auto status = arrow::py::unwrap_data_type(py_data_type, &arrow_data_type);
72
+ GError *error = NULL;
73
+ if (!garrow_error_check(&error, status, "[pyarrow][data-type][to-ruby]"))
74
+ RG_RAISE_ERROR(error);
75
+ auto garrow_data_type = garrow_data_type_new_raw(&arrow_data_type);
76
+ return GOBJ2RVAL(garrow_data_type);
77
+ }
78
+
79
+ static VALUE
80
+ rb_arrow_field_to_python(VALUE self)
45
81
  {
46
82
  auto field = GARROW_FIELD(RVAL2GOBJ(self));
47
83
  auto arrow_field = garrow_field_get_raw(field);
48
84
  auto py_field = arrow::py::wrap_field(arrow_field);
49
- return LONG2NUM((long)(py_field));
85
+ return to_ruby(py_field);
86
+ }
87
+
88
+ static VALUE
89
+ rb_pycall_arrow_field_to_ruby(VALUE self)
90
+ {
91
+ auto py_field = to_python(self);
92
+ std::shared_ptr<arrow::Field> arrow_field;
93
+ auto status = arrow::py::unwrap_field(py_field, &arrow_field);
94
+ GError *error = NULL;
95
+ if (!garrow_error_check(&error, status, "[pyarrow][field][to-ruby]"))
96
+ RG_RAISE_ERROR(error);
97
+ auto garrow_field = garrow_field_new_raw(&arrow_field);
98
+ return GOBJ2RVAL(garrow_field);
50
99
  }
51
100
 
52
101
  static VALUE
53
- rb_arrow_schema_to_python_object_pointer(VALUE self)
102
+ rb_arrow_schema_to_python(VALUE self)
54
103
  {
55
104
  auto schema = GARROW_SCHEMA(RVAL2GOBJ(self));
56
105
  auto arrow_schema = garrow_schema_get_raw(schema);
57
106
  auto py_schema = arrow::py::wrap_schema(arrow_schema);
58
- return LONG2NUM((long)(py_schema));
107
+ return to_ruby(py_schema);
59
108
  }
60
109
 
61
110
  static VALUE
62
- rb_arrow_array_to_python_object_pointer(VALUE self)
111
+ rb_pycall_arrow_schema_to_ruby(VALUE self)
112
+ {
113
+ auto py_schema = to_python(self);
114
+ std::shared_ptr<arrow::Schema> arrow_schema;
115
+ auto status = arrow::py::unwrap_schema(py_schema, &arrow_schema);
116
+ GError *error = NULL;
117
+ if (!garrow_error_check(&error, status, "[pyarrow][schema][to-ruby]"))
118
+ RG_RAISE_ERROR(error);
119
+ auto garrow_schema = garrow_schema_new_raw(&arrow_schema);
120
+ return GOBJ2RVAL(garrow_schema);
121
+ }
122
+
123
+ static VALUE
124
+ rb_arrow_array_to_python(VALUE self)
63
125
  {
64
126
  auto array = GARROW_ARRAY(RVAL2GOBJ(self));
65
127
  auto arrow_array = garrow_array_get_raw(array);
66
128
  auto py_array = arrow::py::wrap_array(arrow_array);
67
- return LONG2NUM((long)(py_array));
129
+ return to_ruby(py_array);
68
130
  }
69
131
 
70
132
  static VALUE
71
- rb_arrow_tensor_to_python_object_pointer(VALUE self)
133
+ rb_pycall_arrow_array_to_ruby(VALUE self)
134
+ {
135
+ auto py_array = to_python(self);
136
+ std::shared_ptr<arrow::Array> arrow_array;
137
+ auto status = arrow::py::unwrap_array(py_array, &arrow_array);
138
+ GError *error = NULL;
139
+ if (!garrow_error_check(&error, status, "[pyarrow][array][to-ruby]"))
140
+ RG_RAISE_ERROR(error);
141
+ auto garrow_array = garrow_array_new_raw(&arrow_array);
142
+ return GOBJ2RVAL(garrow_array);
143
+ }
144
+
145
+ static VALUE
146
+ rb_arrow_tensor_to_python(VALUE self)
72
147
  {
73
148
  auto tensor = GARROW_TENSOR(RVAL2GOBJ(self));
74
149
  auto arrow_tensor = garrow_tensor_get_raw(tensor);
75
150
  auto py_tensor = arrow::py::wrap_tensor(arrow_tensor);
76
- return LONG2NUM((long)(py_tensor));
151
+ return to_ruby(py_tensor);
77
152
  }
78
153
 
79
154
  static VALUE
80
- rb_arrow_column_to_python_object_pointer(VALUE self)
155
+ rb_pycall_arrow_tensor_to_ruby(VALUE self)
156
+ {
157
+ auto py_tensor = to_python(self);
158
+ std::shared_ptr<arrow::Tensor> arrow_tensor;
159
+ auto status = arrow::py::unwrap_tensor(py_tensor, &arrow_tensor);
160
+ GError *error = NULL;
161
+ if (!garrow_error_check(&error, status, "[pyarrow][tensor][to-ruby]"))
162
+ RG_RAISE_ERROR(error);
163
+ auto garrow_tensor = garrow_tensor_new_raw(&arrow_tensor);
164
+ return GOBJ2RVAL(garrow_tensor);
165
+ }
166
+
167
+ static VALUE
168
+ rb_arrow_column_to_python(VALUE self)
81
169
  {
82
170
  auto column = GARROW_COLUMN(RVAL2GOBJ(self));
83
171
  auto arrow_column = garrow_column_get_raw(column);
84
172
  auto py_column = arrow::py::wrap_column(arrow_column);
85
- return LONG2NUM((long)(py_column));
173
+ return to_ruby(py_column);
174
+ }
175
+
176
+ static VALUE
177
+ rb_pycall_arrow_column_to_ruby(VALUE self)
178
+ {
179
+ auto py_column = to_python(self);
180
+ std::shared_ptr<arrow::Column> arrow_column;
181
+ auto status = arrow::py::unwrap_column(py_column, &arrow_column);
182
+ GError *error = NULL;
183
+ if (!garrow_error_check(&error, status, "[pyarrow][column][to-ruby]"))
184
+ RG_RAISE_ERROR(error);
185
+ auto garrow_column = garrow_column_new_raw(&arrow_column);
186
+ return GOBJ2RVAL(garrow_column);
86
187
  }
87
188
 
88
189
  static VALUE
89
- rb_arrow_table_to_python_object_pointer(VALUE self)
190
+ rb_arrow_table_to_python(VALUE self)
90
191
  {
91
192
  auto table = GARROW_TABLE(RVAL2GOBJ(self));
92
193
  auto arrow_table = garrow_table_get_raw(table);
93
194
  auto py_table = arrow::py::wrap_table(arrow_table);
94
- return LONG2NUM((long)(py_table));
195
+ return to_ruby(py_table);
196
+ }
197
+
198
+ static VALUE
199
+ rb_pycall_arrow_table_to_ruby(VALUE self)
200
+ {
201
+ auto py_table = to_python(self);
202
+ std::shared_ptr<arrow::Table> arrow_table;
203
+ auto status = arrow::py::unwrap_table(py_table, &arrow_table);
204
+ GError *error = NULL;
205
+ if (!garrow_error_check(&error, status, "[pyarrow][table][to-ruby]"))
206
+ RG_RAISE_ERROR(error);
207
+ auto garrow_table = garrow_table_new_raw(&arrow_table);
208
+ return GOBJ2RVAL(garrow_table);
95
209
  }
96
210
 
97
211
  static VALUE
98
- rb_arrow_record_batch_to_python_object_pointer(VALUE self)
212
+ rb_arrow_record_batch_to_python(VALUE self)
99
213
  {
100
214
  auto record_batch = GARROW_RECORD_BATCH(RVAL2GOBJ(self));
101
215
  auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
102
216
  auto py_record_batch = arrow::py::wrap_record_batch(arrow_record_batch);
103
- return LONG2NUM((long)(py_record_batch));
217
+ return to_ruby(py_record_batch);
218
+ }
219
+
220
+ static VALUE
221
+ rb_pycall_arrow_record_batch_to_ruby(VALUE self)
222
+ {
223
+ auto py_record_batch = to_python(self);
224
+ std::shared_ptr<arrow::RecordBatch> arrow_record_batch;
225
+ auto status =
226
+ arrow::py::unwrap_record_batch(py_record_batch, &arrow_record_batch);
227
+ GError *error = NULL;
228
+ if (!garrow_error_check(&error, status, "[pyarrow][record-batch][to-ruby]"))
229
+ RG_RAISE_ERROR(error);
230
+ auto garrow_record_batch = garrow_record_batch_new_raw(&arrow_record_batch);
231
+ return GOBJ2RVAL(garrow_record_batch);
104
232
  }
105
233
 
106
234
  extern "C" void
@@ -108,77 +236,143 @@ Init_arrow_pycall(void)
108
236
  {
109
237
  arrow::py::import_pyarrow();
110
238
 
111
- VALUE rbArrow = rb_const_get(rb_cObject, rb_intern("Arrow"));
239
+ auto rbArrow = rb_const_get(rb_cObject, rb_intern("Arrow"));
240
+ auto rbPyArrow = rb_const_get(rb_cObject, rb_intern("PyArrow"));
112
241
 
113
242
  {
114
- VALUE rbArrowBuffer = rb_const_get(rbArrow, rb_intern("Buffer"));
243
+ auto rbArrowBuffer = rb_const_get(rbArrow, rb_intern("Buffer"));
115
244
  rb_define_method(rbArrowBuffer,
116
- "to_python_object_pointer",
117
- (VALUE(*)(ANYARGS))rb_arrow_buffer_to_python_object_pointer,
245
+ "to_python",
246
+ (VALUE(*)(ANYARGS))rb_arrow_buffer_to_python,
247
+ 0);
248
+ }
249
+ {
250
+ auto rbPyArrowBuffer = rb_const_get(rbPyArrow, rb_intern("Buffer"));
251
+ rb_define_method(rbPyArrowBuffer,
252
+ "to_ruby",
253
+ (VALUE(*)(ANYARGS))rb_pycall_arrow_buffer_to_ruby,
118
254
  0);
119
255
  }
120
256
 
121
257
  {
122
- VALUE rbArrowDataType = rb_const_get(rbArrow, rb_intern("DataType"));
258
+ auto rbArrowDataType = rb_const_get(rbArrow, rb_intern("DataType"));
123
259
  rb_define_method(rbArrowDataType,
124
- "to_python_object_pointer",
125
- (VALUE(*)(ANYARGS))rb_arrow_data_type_to_python_object_pointer,
260
+ "to_python",
261
+ (VALUE(*)(ANYARGS))rb_arrow_data_type_to_python,
262
+ 0);
263
+ }
264
+ {
265
+ auto rbPyArrowDataType = rb_const_get(rbPyArrow, rb_intern("DataType"));
266
+ rb_define_method(rbPyArrowDataType,
267
+ "to_ruby",
268
+ (VALUE(*)(ANYARGS))rb_pycall_arrow_data_type_to_ruby,
126
269
  0);
127
270
  }
128
271
 
129
272
  {
130
- VALUE rbArrowField = rb_const_get(rbArrow, rb_intern("Field"));
273
+ auto rbArrowField = rb_const_get(rbArrow, rb_intern("Field"));
131
274
  rb_define_method(rbArrowField,
132
- "to_python_object_pointer",
133
- (VALUE(*)(ANYARGS))rb_arrow_field_to_python_object_pointer,
275
+ "to_python",
276
+ (VALUE(*)(ANYARGS))rb_arrow_field_to_python,
277
+ 0);
278
+ }
279
+ {
280
+ auto rbPyArrowField = rb_const_get(rbPyArrow, rb_intern("Field"));
281
+ rb_define_method(rbPyArrowField,
282
+ "to_ruby",
283
+ (VALUE(*)(ANYARGS))rb_pycall_arrow_field_to_ruby,
134
284
  0);
135
285
  }
136
286
 
137
287
  {
138
- VALUE rbArrowSchema = rb_const_get(rbArrow, rb_intern("Schema"));
288
+ auto rbArrowSchema = rb_const_get(rbArrow, rb_intern("Schema"));
139
289
  rb_define_method(rbArrowSchema,
140
- "to_python_object_pointer",
141
- (VALUE(*)(ANYARGS))rb_arrow_schema_to_python_object_pointer,
290
+ "to_python",
291
+ (VALUE(*)(ANYARGS))rb_arrow_schema_to_python,
292
+ 0);
293
+ }
294
+ {
295
+ auto rbPyArrowSchema = rb_const_get(rbPyArrow, rb_intern("Schema"));
296
+ rb_define_method(rbPyArrowSchema,
297
+ "to_ruby",
298
+ (VALUE(*)(ANYARGS))rb_pycall_arrow_schema_to_ruby,
142
299
  0);
143
300
  }
144
301
 
145
302
  {
146
- VALUE rbArrowArray = rb_const_get(rbArrow, rb_intern("Array"));
303
+ auto rbArrowArray = rb_const_get(rbArrow, rb_intern("Array"));
147
304
  rb_define_method(rbArrowArray,
148
- "to_python_object_pointer",
149
- (VALUE(*)(ANYARGS))rb_arrow_array_to_python_object_pointer,
305
+ "to_python",
306
+ (VALUE(*)(ANYARGS))rb_arrow_array_to_python,
307
+ 0);
308
+ }
309
+ {
310
+ auto rbPyArrowArrayConvertable =
311
+ rb_define_module_under(rbPyArrow, "ArrayConvertable");
312
+ rb_define_method(rbPyArrowArrayConvertable,
313
+ "to_ruby",
314
+ (VALUE(*)(ANYARGS))rb_pycall_arrow_array_to_ruby,
150
315
  0);
151
316
  }
152
317
 
153
318
  {
154
- VALUE rbArrowTensor = rb_const_get(rbArrow, rb_intern("Tensor"));
319
+ auto rbArrowTensor = rb_const_get(rbArrow, rb_intern("Tensor"));
155
320
  rb_define_method(rbArrowTensor,
156
- "to_python_object_pointer",
157
- (VALUE(*)(ANYARGS))rb_arrow_tensor_to_python_object_pointer,
321
+ "to_python",
322
+ (VALUE(*)(ANYARGS))rb_arrow_tensor_to_python,
323
+ 0);
324
+ }
325
+ {
326
+ auto rbPyArrowTensor = rb_const_get(rbPyArrow, rb_intern("Tensor"));
327
+ rb_define_method(rbPyArrowTensor,
328
+ "to_ruby",
329
+ (VALUE(*)(ANYARGS))rb_pycall_arrow_tensor_to_ruby,
158
330
  0);
159
331
  }
160
332
 
161
333
  {
162
- VALUE rbArrowColumn = rb_const_get(rbArrow, rb_intern("Column"));
334
+ auto rbArrowColumn = rb_const_get(rbArrow, rb_intern("Column"));
163
335
  rb_define_method(rbArrowColumn,
164
- "to_python_object_pointer",
165
- (VALUE(*)(ANYARGS))rb_arrow_column_to_python_object_pointer,
336
+ "to_python",
337
+ (VALUE(*)(ANYARGS))rb_arrow_column_to_python,
338
+ 0);
339
+ }
340
+ {
341
+ auto rbPyArrowColumn = rb_const_get(rbPyArrow, rb_intern("Column"));
342
+ rb_define_method(rbPyArrowColumn,
343
+ "to_ruby",
344
+ (VALUE(*)(ANYARGS))rb_pycall_arrow_column_to_ruby,
166
345
  0);
167
346
  }
168
347
 
169
348
  {
170
- VALUE rbArrowTable = rb_const_get(rbArrow, rb_intern("Table"));
349
+ auto rbArrowTable = rb_const_get(rbArrow, rb_intern("Table"));
171
350
  rb_define_method(rbArrowTable,
172
- "to_python_object_pointer",
173
- (VALUE(*)(ANYARGS))rb_arrow_table_to_python_object_pointer,
351
+ "to_python",
352
+ (VALUE(*)(ANYARGS))rb_arrow_table_to_python,
353
+ 0);
354
+ }
355
+ {
356
+ auto rbPyArrowTable = rb_const_get(rbPyArrow, rb_intern("Table"));
357
+ rb_define_method(rbPyArrowTable,
358
+ "to_ruby",
359
+ (VALUE(*)(ANYARGS))rb_pycall_arrow_table_to_ruby,
174
360
  0);
175
361
  }
176
362
 
177
363
  {
178
- VALUE rbArrowRecordBatch = rb_const_get(rbArrow, rb_intern("RecordBatch"));
364
+ auto rbArrowRecordBatch = rb_const_get(rbArrow, rb_intern("RecordBatch"));
179
365
  rb_define_method(rbArrowRecordBatch,
180
- "to_python_object_pointer",
181
- (VALUE(*)(ANYARGS))rb_arrow_record_batch_to_python_object_pointer,
366
+ "to_python",
367
+ (VALUE(*)(ANYARGS))rb_arrow_record_batch_to_python,
368
+ 0);
369
+ }
370
+ {
371
+ auto rbPyArrowRecordBatch =
372
+ rb_const_get(rbPyArrow, rb_intern("RecordBatch"));
373
+ rb_define_method(rbPyArrowRecordBatch,
374
+ "to_ruby",
375
+ (VALUE(*)(ANYARGS))rb_pycall_arrow_record_batch_to_ruby,
182
376
  0);
183
377
  }
184
378
  }
@@ -1,4 +1,4 @@
1
- # Copyright 2017 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright 2017-2018 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -30,4 +30,12 @@ end
30
30
  add_depend_package_path(name, source_dir, build_dir)
31
31
  end
32
32
 
33
+ checking_for(checking_message("pycall"), "%s") do
34
+ pycall_version_path = File.join(__dir__, "..", "..", "pycall-version")
35
+ pycall_version = File.read(pycall_version_path).strip
36
+ pycall_spec = Gem::Specification.find_by_name("pycall", pycall_version)
37
+ $INCFLAGS += " -I#{pycall_spec.gem_dir}/ext/pycall"
38
+ pycall_spec.version
39
+ end
40
+
33
41
  create_makefile("arrow_pycall")
@@ -17,49 +17,70 @@ require "pycall"
17
17
 
18
18
  require "arrow-pycall/version"
19
19
 
20
- begin
21
- major, minor, _ = RUBY_VERSION.split(/\./)
22
- require "#{major}.#{minor}/arrow_pycall.so"
23
- rescue LoadError
24
- require "arrow_pycall.so"
25
- end
26
-
27
- require "arrow-pycall/convertable"
20
+ module PyArrow
21
+ class << self
22
+ def __pyptr__
23
+ @pyarrow ||= PyCall.import_module("pyarrow")
24
+ end
25
+ end
28
26
 
29
- module Arrow
27
+ Buffer = __pyptr__.Buffer
30
28
  class Buffer
31
- include ArrowPyCall::Convertable
29
+ register_python_type_mapping
32
30
  end
33
31
 
32
+ DataType = __pyptr__.lib.DataType
34
33
  class DataType
35
- include ArrowPyCall::Convertable
34
+ register_python_type_mapping
36
35
  end
37
36
 
37
+ Field = __pyptr__.Field
38
38
  class Field
39
- include ArrowPyCall::Convertable
39
+ register_python_type_mapping
40
40
  end
41
41
 
42
+ Schema = __pyptr__.Schema
42
43
  class Schema
43
- include ArrowPyCall::Convertable
44
- end
45
-
46
- class Array
47
- include ArrowPyCall::Convertable
44
+ register_python_type_mapping
48
45
  end
49
46
 
47
+ Tensor = __pyptr__.Tensor
50
48
  class Tensor
51
- include ArrowPyCall::Convertable
49
+ register_python_type_mapping
52
50
  end
53
51
 
52
+ Column = __pyptr__.Column
54
53
  class Column
55
- include ArrowPyCall::Convertable
54
+ register_python_type_mapping
56
55
  end
57
56
 
57
+ Table = __pyptr__.Table
58
58
  class Table
59
- include ArrowPyCall::Convertable
59
+ register_python_type_mapping
60
60
  end
61
61
 
62
+ RecordBatch = __pyptr__.RecordBatch
62
63
  class RecordBatch
63
- include ArrowPyCall::Convertable
64
+ register_python_type_mapping
65
+ end
66
+ end
67
+
68
+ begin
69
+ major, minor, _ = RUBY_VERSION.split(/\./)
70
+ require "#{major}.#{minor}/arrow_pycall.so"
71
+ rescue LoadError
72
+ require "arrow_pycall.so"
73
+ end
74
+
75
+ module PyArrow
76
+ Arrow.constants.each do |name|
77
+ case name.to_s
78
+ when "ChunkedArray"
79
+ when /Array\z/
80
+ py_arrow_array = __pyptr__.lib.__dict__[name.to_s]
81
+ next if py_arrow_array.nil?
82
+ py_arrow_array.__send__(:register_python_type_mapping)
83
+ py_arrow_array.__send__(:include, ArrayConvertable)
84
+ end
64
85
  end
65
86
  end
@@ -1,4 +1,4 @@
1
- # Copyright 2017 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright 2017-2018 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module ArrowPyCall
16
- VERSION = "0.0.2"
16
+ VERSION = "0.0.4"
17
17
  end
@@ -0,0 +1 @@
1
+ >= 1.1.0.rc1
@@ -1,6 +1,6 @@
1
1
  # -*- ruby -*-
2
2
  #
3
- # Copyright 2017 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright 2017-2018 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -18,9 +18,13 @@ clean_white_space = lambda do |entry|
18
18
  entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
19
19
  end
20
20
 
21
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
21
+ base_dir = __dir__
22
+ lib_dir = File.join(base_dir, "lib")
23
+ $LOAD_PATH.unshift(lib_dir)
22
24
  require "arrow-pycall/version"
23
25
 
26
+ pycall_version = File.read(File.join(base_dir, "pycall-version")).strip
27
+
24
28
  Gem::Specification.new do |spec|
25
29
  spec.name = "red-arrow-pycall"
26
30
  spec.version = ArrowPyCall::VERSION
@@ -37,6 +41,7 @@ Gem::Specification.new do |spec|
37
41
  spec.license = "Apache-2.0"
38
42
  spec.files = ["README.md", "Rakefile", "Gemfile", "#{spec.name}.gemspec"]
39
43
  spec.files += [".yardopts"]
44
+ spec.files += ["pycall-version"]
40
45
  spec.files += Dir.glob("lib/**/*.rb")
41
46
  spec.files += Dir.glob("ext/**/*.{c,cpp}")
42
47
  spec.files += Dir.glob("doc/text/*")
@@ -44,7 +49,7 @@ Gem::Specification.new do |spec|
44
49
  spec.test_files += Dir.glob("test/**/*")
45
50
 
46
51
  spec.add_runtime_dependency("red-arrow")
47
- spec.add_runtime_dependency("pycall")
52
+ spec.add_runtime_dependency("pycall", pycall_version)
48
53
 
49
54
  spec.add_development_dependency("bundler")
50
55
  spec.add_development_dependency("rake")
@@ -1,4 +1,4 @@
1
- # Copyright 2017 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright 2017-2018 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -16,33 +16,33 @@ class ToPythonTest < Test::Unit::TestCase
16
16
  test("Buffer") do
17
17
  data = "hello"
18
18
  buffer = Arrow::Buffer.new(data)
19
- assert_equal(data, buffer.to_python.to_pybytes.())
19
+ assert_equal(data, buffer.to_python.to_pybytes)
20
20
  end
21
21
 
22
22
  test("DataType") do
23
23
  data_type = Arrow::BooleanDataType.new
24
24
  assert_equal(data_type.to_s,
25
- data_type.to_python.__str__.())
25
+ data_type.to_python.__str__)
26
26
  end
27
27
 
28
28
  test("Field") do
29
29
  field = Arrow::Field.new("enabled", Arrow::BooleanDataType.new)
30
30
  assert_equal("pyarrow.Field<#{field}>",
31
- field.to_python.__str__.())
31
+ field.to_python.__str__)
32
32
  end
33
33
 
34
34
  test("Schema") do
35
35
  field = Arrow::Field.new("enabled", Arrow::BooleanDataType.new)
36
36
  schema = Arrow::Schema.new([field])
37
37
  assert_equal(schema.to_s,
38
- schema.to_python.__str__.())
38
+ schema.to_python.__str__)
39
39
  end
40
40
 
41
41
  test("Array") do
42
42
  elements = [1, -2, 4]
43
43
  array = Arrow::Int8Array.new(elements)
44
44
  assert_equal(elements,
45
- array.to_python.to_pylist.())
45
+ array.to_python.to_pylist)
46
46
  end
47
47
 
48
48
  test("Tensor") do
@@ -65,7 +65,7 @@ class ToPythonTest < Test::Unit::TestCase
65
65
  shape,
66
66
  strides,
67
67
  names)
68
- assert_equal(<<-TENSOR.chomp, tensor.to_python.to_numpy.().__str__.())
68
+ assert_equal(<<-TENSOR.chomp, tensor.to_python.to_numpy.to_s)
69
69
  [[[ 1 2]
70
70
  [ 3 4]]
71
71
 
@@ -82,7 +82,7 @@ class ToPythonTest < Test::Unit::TestCase
82
82
  array = Arrow::BooleanArray.new([true, false, true])
83
83
  column = Arrow::Column.new(field, array)
84
84
  assert_equal([true, false, true],
85
- column.to_python.to_pylist.())
85
+ column.to_python.to_pylist)
86
86
  end
87
87
 
88
88
  test("Table") do
@@ -91,11 +91,11 @@ class ToPythonTest < Test::Unit::TestCase
91
91
  array = Arrow::BooleanArray.new([true, false, true])
92
92
  column = Arrow::Column.new(field, array)
93
93
  table = Arrow::Table.new(schema, [column])
94
- assert_equal(<<-TABLE.chomp, table.to_python.to_pandas.().to_s)
95
- enabled
96
- 0 True
97
- 1 False
98
- 2 True
94
+ assert_equal(<<-TABLE.chomp, table.to_python.to_pandas.to_s)
95
+ enabled
96
+ 0 True
97
+ 1 False
98
+ 2 True
99
99
  TABLE
100
100
  end
101
101
 
@@ -104,11 +104,11 @@ class ToPythonTest < Test::Unit::TestCase
104
104
  schema = Arrow::Schema.new([field])
105
105
  array = Arrow::BooleanArray.new([true, false, true])
106
106
  record_batch = Arrow::RecordBatch.new(schema, 3, [array])
107
- assert_equal(<<-RECORD_BATCH.chomp, record_batch.to_python.to_pandas.().to_s)
108
- enabled
109
- 0 True
110
- 1 False
111
- 2 True
107
+ assert_equal(<<-RECORD_BATCH.chomp, record_batch.to_python.to_pandas.to_s)
108
+ enabled
109
+ 0 True
110
+ 1 False
111
+ 2 True
112
112
  RECORD_BATCH
113
113
  end
114
114
  end
@@ -0,0 +1,99 @@
1
+ # Copyright 2017 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ class ToRubyTest < Test::Unit::TestCase
16
+ test("Buffer") do
17
+ data = "hello"
18
+ buffer = Arrow::Buffer.new(data)
19
+ py_buffer = buffer.to_python
20
+ assert_equal(data, py_buffer.to_ruby.data.to_s)
21
+ end
22
+
23
+ test("DataType") do
24
+ data_type = Arrow::BooleanDataType.new
25
+ py_data_type = data_type.to_python
26
+ assert_equal(data_type.to_s, py_data_type.to_ruby.to_s)
27
+ end
28
+
29
+ test("Field") do
30
+ field = Arrow::Field.new("enabled", Arrow::BooleanDataType.new)
31
+ assert_equal(field.to_s,
32
+ field.to_python.to_ruby.to_s)
33
+ end
34
+
35
+ test("Schema") do
36
+ field = Arrow::Field.new("enabled", Arrow::BooleanDataType.new)
37
+ schema = Arrow::Schema.new([field])
38
+ assert_equal(schema.to_s,
39
+ schema.to_python.to_ruby.to_s)
40
+ end
41
+
42
+ test("Array") do
43
+ elements = [1, -2, 4]
44
+ array = Arrow::Int8Array.new(elements)
45
+ assert_equal(elements,
46
+ array.to_python.to_ruby.to_a)
47
+ end
48
+
49
+ test("Tensor") do
50
+ raw_data = [
51
+ 1, 2,
52
+ 3, 4,
53
+
54
+ 5, 6,
55
+ 7, 8,
56
+
57
+ 9, 10,
58
+ 11, 12,
59
+ ]
60
+ data = Arrow::Buffer.new(raw_data.pack("c*"))
61
+ shape = [3, 2, 2]
62
+ strides = []
63
+ names = ["a", "b", "c"]
64
+ tensor = Arrow::Tensor.new(Arrow::Int8DataType.new,
65
+ data,
66
+ shape,
67
+ strides,
68
+ names)
69
+ assert_equal(tensor.buffer.data.to_s,
70
+ tensor.to_python.to_ruby.buffer.data.to_s)
71
+ end
72
+
73
+ test("Column") do
74
+ field = Arrow::Field.new("enabled", Arrow::BooleanDataType.new)
75
+ array = Arrow::BooleanArray.new([true, false, true])
76
+ column = Arrow::Column.new(field, array)
77
+ assert_equal([true, false, true],
78
+ column.to_python.to_ruby.to_a)
79
+ end
80
+
81
+ test("Table") do
82
+ field = Arrow::Field.new("enabled", Arrow::BooleanDataType.new)
83
+ schema = Arrow::Schema.new([field])
84
+ array = Arrow::BooleanArray.new([true, false, true])
85
+ column = Arrow::Column.new(field, array)
86
+ table = Arrow::Table.new(schema, [column])
87
+ assert_equal(table.each_column.collect(&:to_a),
88
+ table.to_python.to_ruby.each_column.collect(&:to_a))
89
+ end
90
+
91
+ test("RecordBatch") do
92
+ field = Arrow::Field.new("enabled", Arrow::BooleanDataType.new)
93
+ schema = Arrow::Schema.new([field])
94
+ array = Arrow::BooleanArray.new([true, false, true])
95
+ record_batch = Arrow::RecordBatch.new(schema, 3, [array])
96
+ assert_equal(record_batch.to_s,
97
+ record_batch.to_python.to_ruby.to_s)
98
+ end
99
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red-arrow-pycall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-08 00:00:00.000000000 Z
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: red-arrow
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 1.1.0.rc1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 1.1.0.rc1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -143,12 +143,13 @@ files:
143
143
  - ext/arrow-pycall/arrow-pycall.cpp
144
144
  - ext/arrow-pycall/extconf.rb
145
145
  - lib/arrow-pycall.rb
146
- - lib/arrow-pycall/convertable.rb
147
146
  - lib/arrow-pycall/version.rb
147
+ - pycall-version
148
148
  - red-arrow-pycall.gemspec
149
149
  - test/helper.rb
150
150
  - test/run-test.rb
151
151
  - test/test-to-python.rb
152
+ - test/test-to-ruby.rb
152
153
  homepage: https://github.com/red-data-tools/red-arrow-pycall
153
154
  licenses:
154
155
  - Apache-2.0
@@ -169,12 +170,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
170
  version: '0'
170
171
  requirements: []
171
172
  rubyforge_project:
172
- rubygems_version: 2.5.2
173
+ rubygems_version: 2.5.2.2
173
174
  signing_key:
174
175
  specification_version: 4
175
176
  summary: Red Arrow PyCall is a library that provides converters between Ruby objects
176
177
  for Apache Arrow and Python objects for Apache Arrow.
177
178
  test_files:
179
+ - test/test-to-ruby.rb
178
180
  - test/helper.rb
179
181
  - test/run-test.rb
180
182
  - test/test-to-python.rb
@@ -1,24 +0,0 @@
1
- # Copyright 2017 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- module ArrowPyCall
16
- module Convertable
17
- def to_pycall_object
18
- pointer = FFI::Pointer.new(to_python_object_pointer)
19
- pyobject_struct = PyCall::LibPython::PyObjectStruct.new(pointer)
20
- pyobject_struct.to_ruby
21
- end
22
- alias_method :to_python, :to_pycall_object
23
- end
24
- end