ETA444 / datasafari

DataSafari simplifies complex data science tasks into straightforward, powerful one-liners.
https://datasafari.dev
GNU General Public License v3.0
2 stars 0 forks source link

Implement error handling for hypothesis_predictor_core_c() #95

Closed ETA444 closed 4 months ago

ETA444 commented 4 months ago

Implementation Summary

The function hypothesis_predictor_core_c() performs statistical tests to evaluate the association between two categorical variables using a contingency table. It takes into account the viability of various statistical tests to decide which tests are appropriate given the characteristics of the data. This error handling ensures the inputs are correctly formatted and appropriate for the analysis to prevent runtime errors and logical inconsistencies.

Detailed Error Handling Breakdown

Type Validations

if not isinstance(contingency_table, pd.DataFrame):
    raise TypeError("hypothesis_predictor_core_c(): The 'contingency_table' parameter must be a pandas DataFrame.")
if not isinstance(chi2_viability, bool):
    raise TypeError("hypothesis_predictor_core_c(): The 'chi2_viability' parameter must be a boolean.")
# Similar checks for barnard_viability, boschloo_viability, fisher_viability, and yates_correction_viability
if not isinstance(alternative, str):
    raise TypeError("hypothesis_predictor_core_c(): The 'alternative' parameter must be a string.")

Value Validations

if contingency_table.empty:
    raise ValueError("hypothesis_predictor_core_c(): The input contingency table is empty.")
valid_alternatives = ['two-sided', 'less', 'greater']
if alternative not in valid_alternatives:
    raise ValueError(f"hypothesis_predictor_core_c(): Invalid 'alternative' value. Expected one of {valid_alternatives}, got '{alternative}'.")

Link to Full Code