diff --git a/automol/util/_util.py b/automol/util/_util.py index aa564f2f..b65a936c 100644 --- a/automol/util/_util.py +++ b/automol/util/_util.py @@ -26,7 +26,7 @@ def flatten(lst: Collection) -> Iterator: """Flatten an arbitrarily nested list of lists (iterator). Source: https://stackoverflow.com/a/2158532 . :param lst: An arbitrarily nested list or tuple - :return: An iterator over the flattened list of values + :return: An iterator over the flattened list of values. """ for elem in lst: if isinstance(elem, Iterable) and not isinstance(elem, str | bytes): @@ -195,7 +195,7 @@ def breakby(lst: Sequence, elem) -> tuple[tuple, tuple]: Analogous to ''.split('') for strings. :param lst: The list :param elem: The element to break the list by, gets deleted - :return:The chunks between the break points of the input list + :return:The chunks between the break points of the input list. """ lsts = tuple( tuple(g) for k, g in itertools.groupby(lst, lambda x: x == elem) if not k @@ -203,10 +203,10 @@ def breakby(lst: Sequence, elem) -> tuple[tuple, tuple]: return lsts -def separate_negatives(lst: Sequence)-> tuple [tuple,tuple]: +def separate_negatives(lst: Sequence) -> tuple[tuple, tuple]: """Seperate a list of numbers into negative and nonnegative (>= 0). :param lst: The list - :return: Value for negatives and for positives. + :return: Value for negatives and for non-negatives. """ neg_lst = tuple(val for val in lst if val < 0) pos_lst = tuple(val for val in lst if val >= 0) @@ -228,9 +228,9 @@ def scale_iterable( iterable: Collection[float], scale_factor: float ) -> Collection[float]: """Scale some type of iterable of floats by a scale factor. - :param iterable: A list of numbers. + :param iterable: A list of numbers. :param scale_factor: A factor to scale by. - :return: + :return: The scaled list of numbers. """ if isinstance(iterable, list): iterable = [val * scale_factor for val in iterable] @@ -240,8 +240,13 @@ def scale_iterable( return iterable -def remove_duplicates_with_order(lst: list): - """Remove all duplicates of a list while not reordering the list.""" +def remove_duplicates_with_order(lst: Sequence) -> Sequence: + """Remove all duplicates of a list while not reordering the list. + :param lst: A list. + :return: A list, without duplicates. + Note: To be deprecated + and replaced with calls to more_itertools.unique_justseen. + """ if isinstance(lst, list): lst = [n for i, n in enumerate(lst) if n not in lst[:i]] if isinstance(lst, tuple): diff --git a/automol/util/matrix.py b/automol/util/matrix.py index 32aaf301..f7d754c4 100644 --- a/automol/util/matrix.py +++ b/automol/util/matrix.py @@ -7,9 +7,8 @@ def string(mat: Sequence[Sequence[float]], val_format="{0:>8.3f}") -> str: """Write a matrix to a string. :param mat: matrix to form string with - :type mat: tuple(tuple(float)) - :param precision: number of integers past decimal - :type precision: int + :param val_format: A number-formatting string, such as "{:.3f}" + :return: Matrix as a string """ mat_str = "" for row in mat: diff --git a/automol/util/ring.py b/automol/util/ring.py index fa0c9057..5609d513 100644 --- a/automol/util/ring.py +++ b/automol/util/ring.py @@ -92,9 +92,7 @@ def cycle_item_to_front( :param items: The ring items :parm item: The item to cycle to the font :param end_item: optionally, ensure that this is the last item in the ring - :type end_item: object :returns: The ring items with `item` cycled to the front and `end_item` to the end - :rtype: List[int] """ items = cycle_items_to_front(items, [item]) @@ -135,11 +133,8 @@ def cycle_items_to_back(items: list[object], back_items: list[object]) -> list[o """Cycle ring items until a group of adjacent items is at the end of the list. :param items: The ring items - :type items: List[object] :parm back_items: The item to cycle to the end - :type back_items: List[object] :returns: The ring items `back_items` cycled to the end - :rtype: List[int] """ nitems = len(items) @@ -165,7 +160,6 @@ def cycle_to_split( :param split_pair: The pair of items to split :type split_pair: Tuple[object, object] :return: The ring items with one item in the pair at the start and one at the end - :rtype: List[object] """ nitems = len(items) split_pair = set(split_pair) @@ -201,13 +195,9 @@ def cycle_to_optimal_split( to the end of the list. :param items: The ring items - :type items: List[object] :param split_pairs: Pairs where the cycle can be split - :type split_pairs: List[Tuple[object, object]] :param back_items: Adjacent items that should be as close to the end as possible - :type back_items: List[object] :return: The cycle with the optimal split - :rtype: List[object] """ orig_items = items split_pairs = list(split_pairs)