Skip to content

Commit

Permalink
column names from user could start with numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
mccalluc committed Nov 26, 2024
1 parent b7669f5 commit ef97a5f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dp_wizard/utils/code_generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,14 @@ def _snake_case(name: str):
"""
>>> _snake_case("HW GRADE")
'hw_grade'
>>> _snake_case("123")
'_123'
"""
return re.sub(r"\W+", "_", name.lower())
snake = re.sub(r"\W+", "_", name.lower())
# TODO: More validation in UI so we don't get zero-length strings.
if snake == "" or not re.match(r"[a-z]", snake[0]):
snake = f"_{snake}"
return snake


def _make_imports():
Expand Down

0 comments on commit ef97a5f

Please sign in to comment.