-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented groups of resources (#243)
* Implemented Group class * Implemented package.get_group * Added package.get_group test * Required tabulator>1.24.1 * Fixed linting * Skip compression tests in Python2 * Added `tableschema-sql` to tests require * Added resource.group * Fixed package.save for storage * Implemented `merge_groups` for `package_save` * Added documentation * Updated readme * Updated readme * Updated readme * Updated readme * Fixed tests * Updated readme * Fixed remote schema/dialect
- Loading branch information
Showing
14 changed files
with
385 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name,value | ||
bmw,2016 | ||
tesla,2016 | ||
nissan,2016 |
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,4 @@ | ||
name,value | ||
bmw,2017 | ||
tesla,2017 | ||
nissan,2017 |
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,4 @@ | ||
name,value | ||
bmw,2018 | ||
tesla,2018 | ||
nissan,2018 |
Binary file not shown.
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,12 @@ | ||
{ | ||
"fields": [ | ||
{ | ||
"name": "name", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "value", | ||
"type": "integer" | ||
} | ||
] | ||
} |
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,28 @@ | ||
{ | ||
"name": "datapackage", | ||
"resources": [ | ||
{ | ||
"group": "cars", | ||
"name": "cars-2016", | ||
"path": "cars-2016.csv", | ||
"profile": "tabular-data-resource", | ||
"schema": "cars.schema.json" | ||
}, | ||
{ | ||
"group": "cars", | ||
"name": "cars-2017", | ||
"path": "cars-2017.csv", | ||
"profile": "tabular-data-resource", | ||
"schema": "cars.schema.json" | ||
}, | ||
{ | ||
"group": "cars", | ||
"name": "cars-2018", | ||
"path": "cars-2018.csv.zip", | ||
"profile": "tabular-data-resource", | ||
"compression": "zip", | ||
"format": "csv", | ||
"schema": "cars.schema.json" | ||
} | ||
] | ||
} |
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,54 @@ | ||
from itertools import chain | ||
|
||
|
||
# Module API | ||
|
||
class Group(object): | ||
|
||
# Public | ||
|
||
def __init__(self, resources): | ||
|
||
# Contract checks | ||
assert resources | ||
assert all([resource.tabular for resource in resources]) | ||
assert all([resource.group for resource in resources]) | ||
|
||
# Get props from the resources | ||
self.__name = resources[0].group | ||
self.__headers = resources[0].headers | ||
self.__schema = resources[0].schema | ||
self.__resources = resources | ||
|
||
@property | ||
def name(self): | ||
"""https://github.com/frictionlessdata/datapackage-py#group | ||
""" | ||
return self.__name | ||
|
||
@property | ||
def headers(self): | ||
"""https://github.com/frictionlessdata/datapackage-py#group | ||
""" | ||
return self.__headers | ||
|
||
@property | ||
def schema(self): | ||
"""https://github.com/frictionlessdata/datapackage-py#group | ||
""" | ||
return self.__schema | ||
|
||
def iter(self, **options): | ||
"""https://github.com/frictionlessdata/datapackage-py#group | ||
""" | ||
return chain(*[resource.iter(**options) for resource in self.__resources]) | ||
|
||
def read(self, limit=None, **options): | ||
"""https://github.com/frictionlessdata/datapackage-py#group | ||
""" | ||
rows = [] | ||
for count, row in enumerate(self.iter(**options), start=1): | ||
rows.append(row) | ||
if count == limit: | ||
break | ||
return rows |
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
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
Oops, something went wrong.