Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for groups #10

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions tests/test_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import numpy as np
import pandas as pd
import pytest

from ssb_arbmark_fagfunksjoner.groups import alder_grp
from ssb_arbmark_fagfunksjoner.groups import nace_sn07_17grp
from ssb_arbmark_fagfunksjoner.groups import nace_sn07_47grp
from ssb_arbmark_fagfunksjoner.groups import sektor2_grp
from ssb_arbmark_fagfunksjoner.groups import virk_str_8grp


@pytest.fixture
def sample_df() -> pd.DataFrame:
return pd.DataFrame(
{
"alder": np.random.randint(15, 70, size=100),
"nace_sn07": [f"{i:02d}" for i in np.random.randint(1, 100, size=100)],
"sektor": np.random.choice(["6100", "6500", "1510", "1520"], size=100),
"undersektor": np.random.choice(["007", "008", "009"], size=100),
"ansatte": np.random.randint(0, 300, size=100),
}
)


def test_alder_grp(sample_df):
df = sample_df
df["alder_grp"] = alder_grp(df["alder"])
assert not df["alder_grp"].isnull().any(), "Age group contains null values"
assert df["alder_grp"].dtype == "string", "Age group is not of type string"


def test_nace_sn07_47grp(sample_df):
df = sample_df
df["nace_sn07_47grp"] = nace_sn07_47grp(df["nace_sn07"])
assert (
not df["nace_sn07_47grp"].isnull().any()
), "NACE SN07 47 group contains null values"
assert (
df["nace_sn07_47grp"].dtype == "string"
), "NACE SN07 47 group is not of type string"


def test_nace_sn07_17grp(sample_df):
df = sample_df
df["nace_sn07_17grp"] = nace_sn07_17grp(df["nace_sn07"])
assert (
not df["nace_sn07_17grp"].isnull().any()
), "NACE SN07 17 group contains null values"
assert (
df["nace_sn07_17grp"].dtype == "string"
), "NACE SN07 17 group is not of type string"


def test_sektor2_grp(sample_df):
df = sample_df
df["sektor2_grp"] = sektor2_grp(df["sektor"], df["undersektor"])
assert not df["sektor2_grp"].isnull().any(), "Sector 2 group contains null values"
assert df["sektor2_grp"].dtype == "string", "Sector 2 group is not of type string"


def test_virk_str_8grp(sample_df):
df = sample_df
df["virk_str_8grp"] = virk_str_8grp(df["ansatte"])
assert not df["virk_str_8grp"].isnull().any(), "Employee group contains null values"
assert df["virk_str_8grp"].dtype == "string", "Employee group is not of type string"