使用网状包从 Multidplyr 调用 Python

问题描述

我正在使用 Hadley 的 multidplyr 包对大型数据帧执行一些并行操作。其中一项操作涉及对某些数据进行 base 64 解码,为此我使用了 python 函数。不幸的是,当我尝试使用 multidplyr 扩展它时,python 函数似乎无法在集群中正确复制。这是一个 MWE:

library(reticulate)
library(multidplyr)
library(dplyr)

base64 <- import("base64")

df <- data.frame(groups = c(1,2),data = c("dGVzdA==","dGhpcw=="))

#works
df %>% rowwise() %>%
  mutate(decoded = as.character(base64$b64decode(data)))

cl <- new_cluster(2)
cluster_copy(cl,"base64")

#doesn't work
df %>% group_by(groups) %>%
  partition(cl) %>%
  mutate(
    decoded = base64$b64decode(data)
  ) %>%
  collect()

我得到的错误是:

 Error: Remote computation Failed:
 Problem with `mutate()` input `decoded`.
 x attempt to apply non-function 
 ℹ Input `decoded` is `base64$b64decode(data)`. 
 ℹ The error occurred in group 1: groups = 1.

是否可以将 python 包/函数传递给 multidplyr 集群?怎么样?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)