From ee57673d70e066ce918f79ba0d137d07a6933b09 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 9 Oct 2024 10:17:57 -0700 Subject: [PATCH] Import type hint syntax from the future. Also remove `_ensure_spacing`, no longer used. --- src/nested_pandas/nestedframe/utils.py | 40 ++------------------------ 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/src/nested_pandas/nestedframe/utils.py b/src/nested_pandas/nestedframe/utils.py index 1ca1e0a..0a2767e 100644 --- a/src/nested_pandas/nestedframe/utils.py +++ b/src/nested_pandas/nestedframe/utils.py @@ -1,44 +1,10 @@ +# typing.Self and "|" union syntax don't exist in Python 3.9 +from __future__ import annotations + import ast from enum import Enum -def _ensure_spacing(expr) -> str: - """Ensure that an eval string has spacing""" - single_val_operators = {"+", "-", "*", "/", "%", ">", "<", "|", "&", "~", "="} # omit "(" and ")" - check_for_doubles = {"=", "/", "*", ">", "<"} - double_val_operators = {"==", "//", "**", ">=", "<="} - expr_list = expr - - i = 0 - spaced_expr = "" - while i < len(expr_list): - if expr_list[i] not in single_val_operators: - spaced_expr += expr_list[i] - else: - if expr_list[i] in check_for_doubles: - if "".join(expr_list[i : i + 2]) in double_val_operators: - if spaced_expr[-1] != " ": - spaced_expr += " " - spaced_expr += expr_list[i : i + 2] - if expr_list[i + 2] != " ": - spaced_expr += " " - i += 1 # skip ahead an extra time - else: - if spaced_expr[-1] != " ": - spaced_expr += " " - spaced_expr += expr_list[i] - if expr_list[i + 1] != " ": - spaced_expr += " " - else: - if spaced_expr[-1] != " ": - spaced_expr += " " - spaced_expr += expr_list[i] - if expr_list[i + 1] != " ": - spaced_expr += " " - i += 1 - return spaced_expr - - class NestingType(Enum): """Types of sub-expressions possible in a NestedFrame string expression."""