-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to provide arguments and unique values (#9)
* Update readme for module extras * Add provider arguments and uniqueness support
- Loading branch information
Showing
5 changed files
with
113 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import List, Tuple | ||
|
||
def infer_column_names(col_names, col_types: str) -> List[str]: | ||
""" | ||
Infer column names from column types | ||
""" | ||
# For now, nothing special - but eventually we need to parse things out | ||
if col_names: | ||
return col_names.split(",") | ||
|
||
return col_types.split(",") | ||
|
||
|
||
def parse_column_types(input_string: str) -> List[Tuple[str, List]]: | ||
""" | ||
Parse a string of the format "pyint(1;10),datetime,profile(ssn,birthdate)" and split it by commas with optional parenthese-inclosed arguments. | ||
""" | ||
import re | ||
|
||
pattern = r"([\w\.]+)(\([^)]*\))?" | ||
matches = re.findall(pattern, input_string) | ||
|
||
# Extract the matched groups | ||
result = [ | ||
(match[0], ([try_convert_to_int(val) for val in match[1].strip("()").split(";")] if match[1] else [])) | ||
for match in matches | ||
] | ||
|
||
# print(result) | ||
# [('pyint', ['1', '10']), ('datetime', []), ('profile', ['ssn,birthdate'])] | ||
|
||
return result | ||
|
||
|
||
def try_convert_to_int(s): | ||
try: | ||
return int(s) | ||
except ValueError: | ||
return s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters