[go: up one dir, main page]

Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

mrk-andreev/medium_38f923dd659c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test spark function like evaluate_feature_avg_price_per_merchant

from pyspark.sql.dataframe import DataFrame
from pyspark.sql.functions import avg


def evaluate_feature_avg_price_per_merchant(df: DataFrame) -> DataFrame:
    return df.groupBy('merchant').agg(avg('price').alias('avg_price'))

Using pytest.fixture

import pytest
from pyspark.sql import SparkSession


@pytest.fixture(scope='session')
def spark():
    return SparkSession.builder.getOrCreate()

Requirements

Env:

JAVA_HOME=~/.jdks/corretto-1.8.0_362

Python deps:

pytest==7.2.1
pyspark==3.3.1
pandas==1.5.3