2020-03-02 15:00:49 -05:00
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
|
# or more contributor license agreements. See the NOTICE file
|
|
|
|
|
# distributed with this work for additional information
|
|
|
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
|
|
|
# to you under the Apache License, Version 2.0 (the
|
|
|
|
|
# "License"); you may not use this file except in compliance
|
|
|
|
|
# with the License. You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing,
|
|
|
|
|
# software distributed under the License is distributed on an
|
|
|
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
# KIND, either express or implied. See the License for the
|
|
|
|
|
# specific language governing permissions and limitations
|
|
|
|
|
# under the License.
|
|
|
|
|
|
|
|
|
|
py_to_r.pyarrow.lib.Array <- function(x, ...) {
|
|
|
|
|
schema_ptr <- allocate_arrow_schema()
|
|
|
|
|
array_ptr <- allocate_arrow_array()
|
2020-03-02 17:54:21 -08:00
|
|
|
on.exit({
|
|
|
|
|
delete_arrow_schema(schema_ptr)
|
|
|
|
|
delete_arrow_array(array_ptr)
|
|
|
|
|
})
|
2020-03-02 15:00:49 -05:00
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
x$`_export_to_c`(
|
|
|
|
|
pyarrow_compatible_pointer(array_ptr),
|
|
|
|
|
pyarrow_compatible_pointer(schema_ptr)
|
|
|
|
|
)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2021-06-17 19:02:35 -05:00
|
|
|
Array$import_from_c(array_ptr, schema_ptr)
|
2020-03-02 15:00:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r_to_py.Array <- function(x, convert = FALSE) {
|
|
|
|
|
schema_ptr <- allocate_arrow_schema()
|
|
|
|
|
array_ptr <- allocate_arrow_array()
|
2020-03-02 17:54:21 -08:00
|
|
|
on.exit({
|
|
|
|
|
delete_arrow_schema(schema_ptr)
|
|
|
|
|
delete_arrow_array(array_ptr)
|
|
|
|
|
})
|
2020-03-02 15:00:49 -05:00
|
|
|
|
2020-05-04 16:04:09 -07:00
|
|
|
# Import with convert = FALSE so that `_import_from_c` returns a Python object
|
|
|
|
|
pa <- reticulate::import("pyarrow", convert = FALSE)
|
2021-06-17 19:02:35 -05:00
|
|
|
x$export_to_c(array_ptr, schema_ptr)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
out <- pa$Array$`_import_from_c`(
|
|
|
|
|
pyarrow_compatible_pointer(array_ptr),
|
|
|
|
|
pyarrow_compatible_pointer(schema_ptr)
|
|
|
|
|
)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2020-05-04 16:04:09 -07:00
|
|
|
# But set the convert attribute on the return object to the requested value
|
|
|
|
|
assign("convert", convert, out)
|
|
|
|
|
out
|
2020-03-02 15:00:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
py_to_r.pyarrow.lib.RecordBatch <- function(x, ...) {
|
|
|
|
|
schema_ptr <- allocate_arrow_schema()
|
|
|
|
|
array_ptr <- allocate_arrow_array()
|
2020-03-02 17:54:21 -08:00
|
|
|
on.exit({
|
|
|
|
|
delete_arrow_schema(schema_ptr)
|
|
|
|
|
delete_arrow_array(array_ptr)
|
|
|
|
|
})
|
2020-03-02 15:00:49 -05:00
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
x$`_export_to_c`(
|
|
|
|
|
pyarrow_compatible_pointer(array_ptr),
|
|
|
|
|
pyarrow_compatible_pointer(schema_ptr)
|
|
|
|
|
)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2021-06-17 19:02:35 -05:00
|
|
|
RecordBatch$import_from_c(array_ptr, schema_ptr)
|
2020-03-02 15:00:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r_to_py.RecordBatch <- function(x, convert = FALSE) {
|
|
|
|
|
schema_ptr <- allocate_arrow_schema()
|
|
|
|
|
array_ptr <- allocate_arrow_array()
|
2020-03-02 17:54:21 -08:00
|
|
|
on.exit({
|
|
|
|
|
delete_arrow_schema(schema_ptr)
|
|
|
|
|
delete_arrow_array(array_ptr)
|
|
|
|
|
})
|
2020-04-06 20:05:42 -07:00
|
|
|
|
2020-05-04 16:04:09 -07:00
|
|
|
# Import with convert = FALSE so that `_import_from_c` returns a Python object
|
|
|
|
|
pa <- reticulate::import("pyarrow", convert = FALSE)
|
2021-06-17 19:02:35 -05:00
|
|
|
x$export_to_c(array_ptr, schema_ptr)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
out <- pa$RecordBatch$`_import_from_c`(
|
|
|
|
|
pyarrow_compatible_pointer(array_ptr),
|
|
|
|
|
pyarrow_compatible_pointer(schema_ptr)
|
|
|
|
|
)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2020-05-04 16:04:09 -07:00
|
|
|
# But set the convert attribute on the return object to the requested value
|
|
|
|
|
assign("convert", convert, out)
|
|
|
|
|
out
|
2020-03-02 15:00:49 -05:00
|
|
|
}
|
2020-04-08 10:47:34 +02:00
|
|
|
|
2020-07-07 10:55:55 -07:00
|
|
|
r_to_py.ChunkedArray <- function(x, convert = FALSE) {
|
|
|
|
|
# Import with convert = FALSE so that `_import_from_c` returns a Python object
|
|
|
|
|
pa <- reticulate::import("pyarrow", convert = FALSE)
|
|
|
|
|
out <- pa$chunked_array(x$chunks)
|
|
|
|
|
# But set the convert attribute on the return object to the requested value
|
|
|
|
|
assign("convert", convert, out)
|
|
|
|
|
out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
py_to_r.pyarrow.lib.ChunkedArray <- function(x, ...) {
|
|
|
|
|
ChunkedArray$create(!!!maybe_py_to_r(x$chunks))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r_to_py.Table <- function(x, convert = FALSE) {
|
2022-04-23 09:06:59 -04:00
|
|
|
# TODO(ARROW-16269): Going through RecordBatchReader maintains schema
|
|
|
|
|
# metadata (e.g., extension types) more faithfully than column-wise
|
|
|
|
|
# construction; however, may re-chunk columns unnecessarily.
|
|
|
|
|
py_rbr <- reticulate::r_to_py(as_record_batch_reader(x), convert = FALSE)
|
|
|
|
|
out <- py_rbr$read_all()
|
2020-07-07 10:55:55 -07:00
|
|
|
assign("convert", convert, out)
|
|
|
|
|
out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
py_to_r.pyarrow.lib.Table <- function(x, ...) {
|
2022-04-23 09:06:59 -04:00
|
|
|
# TODO(ARROW-16269): Going through RecordBatchReader maintains schema
|
|
|
|
|
# metadata (e.g., extension types) more faithfully than column-wise
|
|
|
|
|
# construction; however, may re-chunk columns unnecessarily.
|
|
|
|
|
pa <- reticulate::import("pyarrow", convert = FALSE)
|
|
|
|
|
py_rbr <- pa$lib$RecordBatchReader$from_batches(
|
|
|
|
|
x$schema,
|
|
|
|
|
x$to_batches()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
r_rbr <- maybe_py_to_r(py_rbr)
|
|
|
|
|
r_rbr$read_table()
|
2020-12-30 08:28:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
py_to_r.pyarrow.lib.Schema <- function(x, ...) {
|
|
|
|
|
schema_ptr <- allocate_arrow_schema()
|
|
|
|
|
on.exit(delete_arrow_schema(schema_ptr))
|
|
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
x$`_export_to_c`(pyarrow_compatible_pointer(schema_ptr))
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2021-06-17 19:02:35 -05:00
|
|
|
Schema$import_from_c(schema_ptr)
|
2020-12-30 08:28:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r_to_py.Schema <- function(x, convert = FALSE) {
|
|
|
|
|
schema_ptr <- allocate_arrow_schema()
|
|
|
|
|
on.exit(delete_arrow_schema(schema_ptr))
|
|
|
|
|
|
|
|
|
|
# Import with convert = FALSE so that `_import_from_c` returns a Python object
|
|
|
|
|
pa <- reticulate::import("pyarrow", convert = FALSE)
|
2021-06-17 19:02:35 -05:00
|
|
|
x$export_to_c(schema_ptr)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
out <- pa$Schema$`_import_from_c`(
|
|
|
|
|
pyarrow_compatible_pointer(schema_ptr)
|
|
|
|
|
)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2020-12-30 08:28:41 -08:00
|
|
|
# But set the convert attribute on the return object to the requested value
|
|
|
|
|
assign("convert", convert, out)
|
|
|
|
|
out
|
2020-07-07 10:55:55 -07:00
|
|
|
}
|
|
|
|
|
|
2021-05-17 15:25:08 -07:00
|
|
|
py_to_r.pyarrow.lib.Field <- function(x, ...) {
|
|
|
|
|
schema_ptr <- allocate_arrow_schema()
|
|
|
|
|
on.exit(delete_arrow_schema(schema_ptr))
|
|
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
x$`_export_to_c`(pyarrow_compatible_pointer(schema_ptr))
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2021-06-17 19:02:35 -05:00
|
|
|
Field$import_from_c(schema_ptr)
|
2021-05-17 15:25:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r_to_py.Field <- function(x, convert = FALSE) {
|
|
|
|
|
schema_ptr <- allocate_arrow_schema()
|
|
|
|
|
on.exit(delete_arrow_schema(schema_ptr))
|
|
|
|
|
|
|
|
|
|
# Import with convert = FALSE so that `_import_from_c` returns a Python object
|
|
|
|
|
pa <- reticulate::import("pyarrow", convert = FALSE)
|
2021-06-17 19:02:35 -05:00
|
|
|
x$export_to_c(schema_ptr)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
out <- pa$Field$`_import_from_c`(
|
|
|
|
|
pyarrow_compatible_pointer(schema_ptr)
|
|
|
|
|
)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2021-05-17 15:25:08 -07:00
|
|
|
# But set the convert attribute on the return object to the requested value
|
|
|
|
|
assign("convert", convert, out)
|
|
|
|
|
out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
py_to_r.pyarrow.lib.DataType <- function(x, ...) {
|
|
|
|
|
schema_ptr <- allocate_arrow_schema()
|
|
|
|
|
on.exit(delete_arrow_schema(schema_ptr))
|
|
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
x$`_export_to_c`(pyarrow_compatible_pointer(schema_ptr))
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2021-06-17 19:02:35 -05:00
|
|
|
DataType$import_from_c(schema_ptr)
|
2021-05-17 15:25:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r_to_py.DataType <- function(x, convert = FALSE) {
|
|
|
|
|
schema_ptr <- allocate_arrow_schema()
|
|
|
|
|
on.exit(delete_arrow_schema(schema_ptr))
|
|
|
|
|
|
|
|
|
|
# Import with convert = FALSE so that `_import_from_c` returns a Python object
|
|
|
|
|
pa <- reticulate::import("pyarrow", convert = FALSE)
|
2021-06-17 19:02:35 -05:00
|
|
|
x$export_to_c(schema_ptr)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
out <- pa$DataType$`_import_from_c`(
|
|
|
|
|
pyarrow_compatible_pointer(schema_ptr)
|
|
|
|
|
)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2021-05-17 15:25:08 -07:00
|
|
|
# But set the convert attribute on the return object to the requested value
|
|
|
|
|
assign("convert", convert, out)
|
|
|
|
|
out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
py_to_r.pyarrow.lib.RecordBatchReader <- function(x, ...) {
|
|
|
|
|
stream_ptr <- allocate_arrow_array_stream()
|
|
|
|
|
on.exit(delete_arrow_array_stream(stream_ptr))
|
|
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
x$`_export_to_c`(pyarrow_compatible_pointer(stream_ptr))
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2021-07-20 17:16:24 -05:00
|
|
|
RecordBatchReader$import_from_c(stream_ptr)
|
2021-05-17 15:25:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r_to_py.RecordBatchReader <- function(x, convert = FALSE) {
|
|
|
|
|
stream_ptr <- allocate_arrow_array_stream()
|
|
|
|
|
on.exit(delete_arrow_array_stream(stream_ptr))
|
|
|
|
|
|
|
|
|
|
# Import with convert = FALSE so that `_import_from_c` returns a Python object
|
|
|
|
|
pa <- reticulate::import("pyarrow", convert = FALSE)
|
2021-06-17 19:02:35 -05:00
|
|
|
x$export_to_c(stream_ptr)
|
2021-05-17 15:25:08 -07:00
|
|
|
# TODO: handle subclasses of RecordBatchReader?
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
out <- pa$lib$RecordBatchReader$`_import_from_c`(
|
|
|
|
|
pyarrow_compatible_pointer(stream_ptr)
|
|
|
|
|
)
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2021-05-17 15:25:08 -07:00
|
|
|
# But set the convert attribute on the return object to the requested value
|
|
|
|
|
assign("convert", convert, out)
|
|
|
|
|
out
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-07-07 10:55:55 -07:00
|
|
|
maybe_py_to_r <- function(x) {
|
|
|
|
|
if (inherits(x, "python.builtin.object")) {
|
|
|
|
|
# Depending on some auto-convert behavior, x may already be converted
|
|
|
|
|
# or it may still be a Python object
|
|
|
|
|
x <- reticulate::py_to_r(x)
|
|
|
|
|
}
|
|
|
|
|
x
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-23 09:06:59 -04:00
|
|
|
|
|
|
|
|
#' @export
|
|
|
|
|
as_arrow_array.pyarrow.lib.Array <- function(x, ..., type = NULL) {
|
|
|
|
|
as_arrow_array(py_to_r.pyarrow.lib.Array(x), type = type)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# nolint start
|
|
|
|
|
#' @export
|
|
|
|
|
as_chunked_array.pyarrow.lib.ChunkedArray <- function(x, ..., type = NULL) {
|
|
|
|
|
as_chunked_array(py_to_r.pyarrow.lib.ChunkedArray(x), type = type)
|
|
|
|
|
}
|
|
|
|
|
# nolint end
|
|
|
|
|
|
|
|
|
|
#' @export
|
|
|
|
|
as_record_batch.pyarrow.lib.RecordBatch <- function(x, ..., schema = NULL) {
|
|
|
|
|
as_record_batch(py_to_r.pyarrow.lib.RecordBatch(x), schema = schema)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#' @export
|
|
|
|
|
as_arrow_table.pyarrow.lib.RecordBatch <- function(x, ..., schema = NULL) {
|
|
|
|
|
as_arrow_table(py_to_r.pyarrow.lib.RecordBatch(x), schema = schema)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Some of these function names are longer than 40 characters
|
|
|
|
|
# (but have to be named such because of S3 method naming)
|
|
|
|
|
# nolint start
|
|
|
|
|
#' @export
|
|
|
|
|
as_record_batch_reader.pyarrow.lib.RecordBatch <- function(x, ...) {
|
|
|
|
|
as_record_batch_reader(py_to_r.pyarrow.lib.RecordBatch(x))
|
|
|
|
|
}
|
|
|
|
|
# nolint end
|
|
|
|
|
|
|
|
|
|
#' @export
|
|
|
|
|
as_record_batch.pyarrow.lib.Table <- function(x, ..., schema = NULL) {
|
|
|
|
|
as_record_batch(py_to_r.pyarrow.lib.Table(x), schema = schema)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#' @export
|
|
|
|
|
as_arrow_table.pyarrow.lib.Table <- function(x, ..., schema = NULL) {
|
|
|
|
|
as_arrow_table(py_to_r.pyarrow.lib.Table(x), schema = schema)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#' @export
|
|
|
|
|
as_record_batch_reader.pyarrow.lib.Table <- function(x, ...) {
|
|
|
|
|
as_record_batch_reader(py_to_r.pyarrow.lib.Table(x))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#' @export
|
|
|
|
|
as_schema.pyarrow.lib.Schema <- function(x, ...) {
|
|
|
|
|
py_to_r.pyarrow.lib.Schema(x)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#' @export
|
|
|
|
|
as_data_type.pyarrow.lib.Field <- function(x, ...) {
|
|
|
|
|
as_data_type(py_to_r.pyarrow.lib.Field(x))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#' @export
|
|
|
|
|
as_data_type.pyarrow.lib.DataType <- function(x, ...) {
|
|
|
|
|
as_data_type(py_to_r.pyarrow.lib.DataType(x))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# nolint start
|
|
|
|
|
#' @export
|
|
|
|
|
as_record_batch_reader.pyarrow.lib.RecordBatchReader <- function(x, ...) {
|
|
|
|
|
py_to_r.pyarrow.lib.RecordBatchReader(x)
|
|
|
|
|
}
|
|
|
|
|
# nolint end
|
|
|
|
|
|
2020-04-08 10:47:34 +02:00
|
|
|
#' Install pyarrow for use with reticulate
|
|
|
|
|
#'
|
|
|
|
|
#' `pyarrow` is the Python package for Apache Arrow. This function helps with
|
|
|
|
|
#' installing it for use with `reticulate`.
|
|
|
|
|
#'
|
|
|
|
|
#' @param envname The name or full path of the Python environment to install
|
|
|
|
|
#' into. This can be a virtualenv or conda environment created by `reticulate`.
|
|
|
|
|
#' See `reticulate::py_install()`.
|
|
|
|
|
#' @param nightly logical: Should we install a development version of the
|
|
|
|
|
#' package? Default is to use the official release version.
|
|
|
|
|
#' @param ... additional arguments passed to `reticulate::py_install()`.
|
|
|
|
|
#' @export
|
|
|
|
|
install_pyarrow <- function(envname = NULL, nightly = FALSE, ...) {
|
|
|
|
|
if (nightly) {
|
2025-10-07 00:03:35 +09:00
|
|
|
reticulate::py_install(
|
|
|
|
|
"pyarrow",
|
|
|
|
|
envname = envname,
|
|
|
|
|
...,
|
2020-04-08 10:47:34 +02:00
|
|
|
# Nightly for pip
|
2025-10-07 00:03:35 +09:00
|
|
|
pip_options = c(
|
|
|
|
|
"--extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple",
|
|
|
|
|
"--pre",
|
|
|
|
|
"--upgrade"
|
|
|
|
|
),
|
2020-04-08 10:47:34 +02:00
|
|
|
# Nightly for conda
|
|
|
|
|
channel = "arrow-nightlies"
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
reticulate::py_install("pyarrow", envname = envname, ...)
|
|
|
|
|
}
|
|
|
|
|
}
|
ARROW-15173: [R] Provide backward compatibility for bridge to older versions of pyarrow
This PR updates the pointer logic that changed in #12011 (ARROW-15169) to make sure that users can use the arrow R package to communicate with pyarrow that hasn't been upgraded yet.
Should work with:
``` bash
pip3 install pyarrow
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
and:
``` bash
pip3 install pyarrow --extra-index-url https://repo.fury.io/arrow-nightlies/ --pre --upgrade
```
``` r
pa <- reticulate::import("pyarrow", convert = FALSE)
py <- pa$array(c(1, 2, 3))
reticulate::py_to_r(py)
#> [
#> 1,
#> 2,
#> 3
#> ]
```
...but we don't have a good way to test against the old pyarrow version in our tests (unless @jonkeane can think of one!)
Closes #12062 from paleolimbot/r-bridge-compat
Authored-by: Dewey Dunnington <dewey@fishandwhistle.net>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
2022-01-12 13:42:18 -06:00
|
|
|
|
2022-01-19 16:25:16 -06:00
|
|
|
pyarrow_compatible_pointer <- function(ptr) {
|
2024-02-07 10:29:46 -04:00
|
|
|
# GH-39933: Workaround because there is no built-in way to send a
|
|
|
|
|
# 64-bit integer to Python from an R object
|
|
|
|
|
py <- reticulate::import_builtins(convert = FALSE)
|
|
|
|
|
addr <- external_pointer_addr_character(ptr)
|
|
|
|
|
py$int(addr)
|
2022-01-19 16:25:16 -06:00
|
|
|
}
|