为什么在两个 Polars 数据帧之间执行左连接时会出现 ComputeError?

问题描述 投票:0回答:1

下面的代码片段位于函数内部,并且该函数位于类内部。我用的是极地而不是熊猫。我尝试运行该函数,但在执行左连接时它显示错误。

import polars as pl

inventory = pl.from_pandas(inventory)

# If a production order is provided, merge the inventory and production order information
if isinstance(self.production_order, pl.DataFrame) and (self.production_order.shape[0] > 0):
    inventory = inventory.join(self.production_order,on='material_number', how='left')

我收到以下错误

计算错误:只有在同一全局字符串缓存下创建分类数据类型时,才会发生分类数据类型的连接/或比较。提示:设置全局 StringCache

我尝试使用“with pl.StringCache():”,然后执行连接,但它仍然显示相同的错误。我可以做什么来修复它?

left-join python-polars
1个回答
0
投票

创建表中的分类时,您必须设置字符串缓存。这可以通过在程序开始时设置

pl.enable_string_cache()
来对整个脚本/程序完成。

或者这只能在创建表时完成,然后清理字符串缓存。

with pl.StringCache(): # set string cache for duration of inventory creation.
    inventory = pl.from_pandas(inventory)

if isinstance(self.production_order, pl.DataFrame) and (self.production_order.shape[0] > 0):
    inventory = inventory.join(self.production_order,on='material_number', how='left')
© www.soinside.com 2019 - 2024. All rights reserved.