简体   繁体   中英

How to pass dataframe as argument in robot file?

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

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}

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

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM