Skip to content

Commit

Permalink
Improve code, interace for aa.plot_set_legend
Browse files Browse the repository at this point in the history
  • Loading branch information
breimanntools committed Sep 25, 2023
1 parent 452f9aa commit d373f68
Show file tree
Hide file tree
Showing 90 changed files with 505 additions and 208 deletions.
6 changes: 5 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ or a custom testing template:
1. Normal Cases Test Class:
- Name: 'Test[TARGET FUNCTION NAME]'.
- Objective: Test EACH parameter *INDIVIDUALLY*.
- Tests: For EACH parameter, at least 10 positive and 10 negative tests.
- Tests: Test EACH parameter, at least 10 positive and 10 negative tests for this class.
2. Complex Cases Test Class:
- Name: 'Test[TARGET FUNCTION NAME]Complex'.
Expand All @@ -400,3 +400,7 @@ or a custom testing template:
Reminder: In Normal Cases, it's crucial to test parameters individually.
"
You can run this prompt multiple times or ask to continue. After copy-pasting all results into
your final testing script. Copy this script and provide it to ChatGPT with the prompt to remove
redundancy and to make it more concise.
Binary file modified aaanalysis/__pycache__/utils.cpython-39.pyc
Binary file not shown.
Binary file modified aaanalysis/_utils/__pycache__/_utils_check.cpython-39.pyc
Binary file not shown.
Binary file modified aaanalysis/_utils/__pycache__/utils_cpp.cpython-39.pyc
Binary file not shown.
64 changes: 32 additions & 32 deletions aaanalysis/_utils/_utils_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@


# Type checking functions
def check_number_val(name=None, val=None, accept_none=False, just_int=False):
"""Check if value is float"""
if just_int is None:
raise ValueError("'just_int' must be specified")
if accept_none and val is None:
return None
valid_types = (int,) if just_int else (float, int)
type_description = "int" if just_int else "float or int"
if not isinstance(val, valid_types):
raise ValueError(f"'{name}' ({val}) should be {type_description})")


def check_number_range(name=None, val=None, min_val=0, max_val=None, accept_none=False, just_int=None):
"""Check if value of given name is within defined range"""
if just_int is None:
Expand All @@ -24,60 +36,48 @@ def check_number_range(name=None, val=None, min_val=0, max_val=None, accept_none
raise ValueError(error)


def check_number_val(name=None, val=None, accept_none=False, just_int=False):
"""Check if value is float"""
check_types = [int] if just_int else [float, int]
if accept_none and val is None:
return None
if type(val) not in [float, int]:
error = f"'{name}' ({val}) should be float"
if not just_int:
error += " or int."
else:
error += "."
raise ValueError(error)


def check_str(name=None, val=None, accept_none=False):
""""""
"""Check type string"""
if accept_none and val is None:
return None
if not isinstance(val, str):
raise ValueError(f"'{name}' ('{val}') should be string.")


def check_bool(name=None, val=None):
""""""
if type(val) != bool:
"""Check if the provided value is a boolean."""
if not isinstance(val, bool):
raise ValueError(f"'{name}' ({val}) should be bool.")


def check_dict(name=None, val=None, accept_none=False):
""""""
error = f"'{name}' ('{val}') should be a dictionary"
if accept_none:
error += " or None."
else:
error += "."
"""Check if the provided value is a dictionary."""
if accept_none and val is None:
return None
if not isinstance(val, dict):
error = f"'{name}' ({val}) should be a dictionary"
error += " or None." if accept_none else "."
raise ValueError(error)


def check_tuple(name=None, val=None, n=None):
def check_tuple(name=None, val=None, n=None, check_n=True):
""""""
error = f"'{name}' ('{val}') should be a tuple"
if n is not None:
error += f" with {n} elements."
else:
error += "."
if not isinstance(val, tuple):
raise ValueError(error)
if n is not None and len(val) != n:
raise ValueError(error)
raise ValueError(f"'{name}' ({val}) should be a tuple.")
if check_n and n is not None and len(val) != n:
raise ValueError(f"'{name}' ({val}) should be a tuple with {n} elements.")


# Check special types
def check_ax(ax=None, accept_none=False):
""""""
import matplotlib.axes
if accept_none and ax is None:
return None
if not isinstance(ax, matplotlib.axes.Axes):
raise ValueError(f"'ax' (type={type(ax)}) should be mpl.axes.Axes or None.")

# TODO check these functions if used
# Array checking functions
def check_feat_matrix(X=None, names=None, labels=None):
"""Transpose matrix and check if X and y match (y can be labels or names). Transpose back otherwise """
Expand Down
Binary file modified aaanalysis/cpp/__pycache__/cpp_plot.cpython-39.pyc
Binary file not shown.
Binary file modified aaanalysis/plotting/__pycache__/plot_set_legend_.cpython-39.pyc
Binary file not shown.
Loading

0 comments on commit d373f68

Please sign in to comment.