-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
14 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,8 +92,9 @@ def close_file(file): | |
if file and file is not sys.stdout and file is not sys.stdin: | ||
file.close() | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------ # | ||
def to_type(s): | ||
def str_to_type(s): | ||
""" Convert string s to a proper type: int, float or boolean """ | ||
|
||
if s in ('True', 'true', 'False', 'false'): # to boolean | ||
|
@@ -104,6 +105,7 @@ def to_type(s): | |
except (ValueError, TypeError): | ||
return s # no conversion possible -> string | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------ # | ||
def read_csv(in_file=None, encoding=None, newline='', name='', detect_types=False, | ||
dialect='excel', **fmtparams): | ||
|
@@ -278,7 +280,7 @@ def import_list_dicts(self, data, name=None, detect_types=False): | |
if TNAME_COLUMN_DELIMITER not in str(f) else f for f in (data[0].keys())] | ||
|
||
self.table = [list(r.values()) for r in data] if not detect_types else [ | ||
[to_type(v) for v in r.values()] for r in data] | ||
[str_to_type(v) for v in r.values()] for r in data] | ||
|
||
else: | ||
raise ValueError('[email protected]_list_dicts: Unexpected data format') | ||
|
@@ -307,7 +309,7 @@ def import_dict_lists(self, data, name=None, detect_types=False): | |
|
||
for c, f in enumerate(data.keys()): | ||
for r, v in enumerate(data[f]): | ||
self.table[r][c] = v if not detect_types else to_type(v) | ||
self.table[r][c] = v if not detect_types else str_to_type(v) | ||
self._redimension() | ||
else: | ||
raise ValueError('[email protected]_dict_lists: Unexpected data format') | ||
|
@@ -336,7 +338,7 @@ def import_list_lists(self, data, header=True, name=None, detect_types=False): | |
if not detect_types: | ||
self.table = data[1:] if header else data | ||
else: | ||
self.table = [[to_type(v) for v in r] for r in data[1:]] | ||
self.table = [[str_to_type(v) for v in r] for r in data[1:]] | ||
|
||
self._redimension() | ||
|
||
|