Closed ETA444 closed 7 months ago
Implementation Summary:
The error handling for explore_df()
ensures that the function operates with valid inputs, avoiding unexpected behaviors or runtime errors. This involves checking the types and values of the function's parameters, and raising appropriate exceptions when issues are found.
Error Handling:
if not isinstance(df, pd.DataFrame):
raise TypeError("explore_df(): The df parameter must be a pandas DataFrame.")
if not isinstance(method, str):
raise TypeError("explore_df(): The method parameter must be a string.\nExample: method = 'all'")
if not isinstance(output, str):
raise TypeError("explore_df(): The output parameter must be a string.\nExample: output = 'print'")
if df.empty:
raise ValueError("explore_df(): The input DataFrame is empty.")
valid_methods = ['na', 'desc', 'head', 'info', 'all']
if method.lower() not in valid_methods:
raise ValueError(f"explore_df(): Invalid method '{method}'. Valid options are: {', '.join(valid_methods)}.")
if output.lower() not in ['print', 'return']:
raise ValueError("explore_df(): Invalid output method. Choose 'print' or 'return'.")
if 'buf' in kwargs and method.lower() == 'info':
raise ValueError("explore_df(): 'buf' parameter is not supported in the 'info' method within explore_df.")
See the Full Function:
The full implementation can be found in the datasafari repository.
Implement error handling for each user input of the function.