-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add messytables -> jts converter, with docs. Fixes #40
- Loading branch information
Showing
7 changed files
with
101 additions
and
38 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 |
---|---|---|
|
@@ -198,4 +198,3 @@ def dicts(self, sample=False): | |
|
||
def __repr__(self): | ||
return "RowSet(%s)" % self.name | ||
|
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,42 @@ | ||
''' | ||
Convert a rowset to the json table schema (http://www.dataprotocols.org/en/latest/json-table-schema.html) | ||
''' | ||
|
||
import messytables | ||
import jsontableschema | ||
|
||
MESSYTABLES_TO_JTS_MAPPING = { | ||
messytables.types.StringType: 'string', | ||
messytables.types.IntegerType: 'integer', | ||
messytables.types.FloatType: 'number', | ||
messytables.types.DecimalType: 'number', | ||
messytables.types.DateType: 'date', | ||
messytables.types.DateUtilType: 'date' | ||
} | ||
|
||
|
||
def celltype_as_string(celltype): | ||
return MESSYTABLES_TO_JTS_MAPPING[celltype.__class__] | ||
|
||
|
||
def rowset_as_jts(rowset, headers=None, types=None): | ||
''' Create a json table schema from a rowset | ||
''' | ||
_, headers = messytables.headers_guess(rowset.sample) | ||
types = map(celltype_as_string, messytables.type_guess(rowset.sample)) | ||
|
||
return headers_and_typed_as_jts(headers, types) | ||
|
||
|
||
def headers_and_typed_as_jts(headers, types): | ||
''' Create a json table schema from headers and types as | ||
returned from :meth:`~messytables.headers.headers_guess` and :meth:`~messytables.types.type_guess`. | ||
''' | ||
j = jsontableschema.JSONTableSchema() | ||
|
||
for field_id, field_type in zip(headers, types): | ||
j.add_field(field_id=field_id, | ||
label=field_id, | ||
field_type=field_type) | ||
|
||
return j |
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ chardet==2.1.1 | |
python-dateutil>=1.5.0,<2.0.0 | ||
httpretty | ||
nose | ||
requests>=1.0 | ||
requests>=1.0 | ||
json-table-schema |
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