如何将数据帧传递为机器人文件中的参数?

发布于 2025-01-25 04:13:50 字数 410 浏览 2 评论 0原文

我将数据帧传递到类方法,当我运行PY文件时,其工作正常。但是当我在机器人中调用该方法时,我会遇到错误,因为“字符串索引必须是整数”。以下是参考的代码。

python文件(虚拟)

class Dummy:
    def case1(self,df1,df2):
        #operation
#reading file and creating dataframe here
obj=Dummy()
obj.case1(df1,df2)

机器人文件

*** Settings ***
Library    Dummy.py


*** Test Cases ***
Example
    ${result}=    Dummy.case1    df1    df2

I am passing dataframe to class method and when I run py file its working fine.But when I call that method in robot I am getting error as "string indices must be integers". below is the code for ref.

python file(Dummy.py)

class Dummy:
    def case1(self,df1,df2):
        #operation
#reading file and creating dataframe here
obj=Dummy()
obj.case1(df1,df2)

robot file

*** Settings ***
Library    Dummy.py


*** Test Cases ***
Example
    ${result}=    Dummy.case1    df1    df2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江湖彼岸 2025-02-01 04:13:50

您可以像其他任何变量一样传递数据帧。无需对其进行任何不同。这里的重要问题是您是如何创建它的?真的是数据框架吗?

下面的示例应起作用:

.py

import pandas

class MyLibrary:

    def Show_Size(self,data_frame):
        return data_frame.size

    def Create_Dataframe(slef):
        return pandas.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]],index=[4, 5, 6], columns=['A', 'B', 'C'])

机器人

*** Settings ***
Library           MyLibrary.py

  
*** Test Cases ***   
Example 
    ${data_frame_variable}=    MyLibrary.Create_Dataframe               
    ${result}=    MyLibrary.Show_Size    ${data_frame_variable}
    Log    ${result}

You can pass dataframe as you would any other variable. There is no need to treat it any different. Important question here is how did you create it? Was it realy a dataframe?

below example should work:

.py

import pandas

class MyLibrary:

    def Show_Size(self,data_frame):
        return data_frame.size

    def Create_Dataframe(slef):
        return pandas.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]],index=[4, 5, 6], columns=['A', 'B', 'C'])

robot

*** Settings ***
Library           MyLibrary.py

  
*** Test Cases ***   
Example 
    ${data_frame_variable}=    MyLibrary.Create_Dataframe               
    ${result}=    MyLibrary.Show_Size    ${data_frame_variable}
    Log    ${result}
夏尔 2025-02-01 04:13:50

我能够使用变量文件为Pyspark DataFrame做到这一点。

您可以创建一个变量文件,并创建一个数据框作为该文件中的变量,然后从.robot文件

变量。

from pyspark.sql.session import SparkSession

class create_df:
       def create_dataframe():
              #code to crate dataframe
              return dataframe

a = create_df()

variable_df = a.create_dataframe

调用

*** Settings ***
Documentation     Test Suite contains Tests cases for demo
Resource          ../Resource/Resource.txt
Variables         ../Variables/myvariables.py

*** Test Cases ***
This_is_not_null_check
    Column Is Not NULL Check    ${variable_df}    Category

I was able to do it for pyspark dataframe using variables files.

You can create a variable file and create a dataframe as a variable in that file and then call the variable from .robot file..

Example myvariables.py

from pyspark.sql.session import SparkSession

class create_df:
       def create_dataframe():
              #code to crate dataframe
              return dataframe

a = create_df()

variable_df = a.create_dataframe

Exmaple .ROBOT file

*** Settings ***
Documentation     Test Suite contains Tests cases for demo
Resource          ../Resource/Resource.txt
Variables         ../Variables/myvariables.py

*** Test Cases ***
This_is_not_null_check
    Column Is Not NULL Check    ${variable_df}    Category
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文