<commit_before>"""Runs checks on the data to help capture some errors faster and provides better error messages. 

Functions:
    | *assert_probabilities()* ensures that probability values are between 0 and 1. 
    | *assert_weights()* ensures that sample weights are not negatives. 
    | *assert_not_unique()* return an assertion error if the array has non unique values. 
    | *assert_response_status()* checks that the response values are in ("in", "rr", "nr", "uk").
    | *assert_brr_number_psus()* checks that the number of psus is a multiple of 2. 
"""

from typing import TypeVar, Type, Any, Dict, Optional, Tuple, Union

import numpy as np
import pandas as pd
from samplics.utils import formats
from samplics.utils.types import Array, Number, StringNumber


def assert_probabilities(probabilities: Array) -> None:
    if probabilities.any() > 1:
        raise ValueError("Probabilities cannot be greater than 1")
    elif probabilities.any() < 0:
        raise ValueError("Probabilities must be positive")


def assert_weights(weights: Array) -> None:
    if weights.any() < 0:
        raise ValueError("Sample weights must be positive values")


def assert_not_unique(array_unique_values: Array) -> None:
    if np.unique(array_unique_values).size != len(array_unique_values):
        raise AssertionError(
            "array_unique_values must contains unique values identifying all the units in the sampling frame."
        )


def assert_response_status(response_status: Any, response_dict: Dict[Any, Any]) -> None:<commit_msg>addressed possible unbound<commit_after>"""Runs checks on the data to help capture some errors faster and provides better error messages. 

Functions:
    | *assert_probabilities()* ensures that probability values are between 0 and 1. 
    | *assert_weights()* ensures that sample weights are not negatives. 
    | *assert_not_unique()* return an assertion error if the array has non unique values. 
    | *assert_response_status()* checks that the response values are in ("in", "rr", "nr", "uk").
    | *assert_brr_number_psus()* checks that the number of psus is a multiple of 2. 
"""

from typing import Any, Dict

import numpy as np
from samplics.utils.types import Array


def assert_probabilities(probabilities: Array) -> None:
    if probabilities.any() > 1:
        raise ValueError("Probabilities cannot be greater than 1")
    elif probabilities.any() < 0:
        raise ValueError("Probabilities must be positive")


def assert_weights(weights: Array) -> None:
    if weights.any() < 0:
        raise ValueError("Sample weights must be positive values")


def assert_not_unique(array_unique_values: Array) -> None:
    if np.unique(array_unique_values).size != len(array_unique_values):
        raise AssertionError(
            "array_unique_values must contains unique values identifying all the units in the sampling frame."
        )


def assert_response_status(response_status: Any, response_dict: Dict[Any, Any]) -> None:
{'fraction_non_alphanumeric': 0.08788996980878899, 'fraction_numerical': 0.004696410600469641, 'mean_word_length': 4.062818336162988, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6317429', 'n_tokens_mistral': 833, 'n_tokens_neox': 797, 'n_words': 316}