您的位置:

关于cubes的ArgumentError("Unknown cut type %s" % cut_type)

  发布时间:2023-01-27 00:30:01
报错的原因是由cubes模块在遇到未知的cut_type参数时产生的。这通常是由于程序传递了一个不被cubes支持的cut_type参数值导致的。如果您不确定使用的cut_type参数是否正确,可以查看cubes文档或示例代码,了解cubes支持的cut_type参数值和使用方法。假设我们有一个cubes模型,名为"sales_model",并且我们想要对它进行切片。

报错的原因

ArgumentError("Unknown cut type %s" % cut_type)是由cubes模块在遇到未知的cut_type参数时产生的。这通常是由于程序传递了一个不被cubes支持的cut_type参数值导致的。可能您需要检查您的代码中cut_type参数的值是否正确。

如何解决

解决这个问题的方法是检查代码中cut_type参数的值是否正确。首先,确保您使用的是cubes支持的cut_type参数值。如果您使用了不被cubes支持的cut_type参数值,请更改它们为支持的值。其次,请确保您使用的是正确的参数名称。如果您使用了错误的参数名称,请更改它们为正确的名称。

如果您不确定使用的cut_type参数是否正确,可以查看cubes文档或示例代码,了解cubes支持的cut_type参数值和使用方法。

如果您已经确认了参数是正确的,并且还是报错,那么您可以考虑更新cubes模块。

使用例子

是的,下面是一个例子。假设我们有一个cubes模型,名为"sales_model",并且我们想要对它进行切片。

正确的写法应该是这样的:


from cubes import Workspace

# create a workspace and load the sales model
workspace = Workspace()
workspace.register_default_store("sql", url="sqlite:///data.sqlite")
workspace.import_model("model.json")

# create a browser and slice the cube
browser = workspace.browser("sales_model")
cell = browser.full_cube()
cell = cell.drilldown("date", "year")
cell = cell.drilldown("product", "category")
result = browser.aggregate(cell)

而错误的写法应该像这样:


from cubes import Workspace

# create a workspace and load the sales model
workspace = Workspace()
workspace.register_default_store("sql", url="sqlite:///data.sqlite")
workspace.import_model("model.json")

# create a browser and slice the cube
browser = workspace.browser("sales_model")
cell = browser.full_cube()
cell = cell.drilldown("year","date")  # 错误的参数顺序
cell = cell.drilldown("category", "product") #错误的参数顺序
result = browser.aggregate(cell)

这个例子中,在第二次调用drilldown函数时,我们传递了错误的参数顺序,导致了"year"不是一个被cubes支持的cut_type参数值,就会抛出 "ArgumentError("Unknown cut type %s" % cut_type)"。而正确的方法是先传入维度的名称,再传入其值。