Skip to content

Commit

Permalink
Import type hint syntax from the future.
Browse files Browse the repository at this point in the history
Also remove `_ensure_spacing`, no longer used.
  • Loading branch information
gitosaurus committed Oct 9, 2024
1 parent 850bd03 commit ee57673
Showing 1 changed file with 3 additions and 37 deletions.
40 changes: 3 additions & 37 deletions src/nested_pandas/nestedframe/utils.py
Original file line number Diff line number Diff line change
@@ -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."""

Expand Down

0 comments on commit ee57673

Please sign in to comment.