-
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.
Merge branch 'features/postprocessing'
- Loading branch information
Showing
9 changed files
with
430 additions
and
45 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,14 @@ | ||
""" | ||
Entrypoint module, in case you use `python -mtabular`. | ||
Why does this file exist, and why __main__? For more info, read: | ||
- https://www.python.org/dev/peps/pep-0338/ | ||
- https://docs.python.org/2/using/cmdline.html#cmdoption-m | ||
- https://docs.python.org/3/using/cmdline.html#cmdoption-m | ||
""" | ||
from tabular.cli import main | ||
|
||
if __name__ == "__main__": | ||
main() |
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,62 @@ | ||
""" | ||
Module that contains the command line app. | ||
""" | ||
import click | ||
from datapackage import Package, exceptions | ||
import pandas as pd | ||
|
||
|
||
def _test(ctx, package): | ||
""" | ||
""" | ||
p = Package(package) | ||
for r in p.resources: | ||
try: | ||
r.read(keyed=True) | ||
fks = r.descriptor['schema'].get('foreignKeys', []) | ||
for fk in fks: | ||
if fk.get('fields') == 'profile': | ||
profile = p.get_resource(fk['reference']['resource']) | ||
field_names = set([ | ||
field['name'] | ||
for field in profile.descriptor['schema']['fields'] | ||
]) | ||
field_names.remove('timeindex') | ||
profile_names = set( | ||
pd.DataFrame(r.read(keyed=True))['profile']) | ||
|
||
diff = field_names.symmetric_difference(profile_names) | ||
if len(diff) > 0: | ||
for d in diff: | ||
print( | ||
("Foreign key error for {} in " | ||
" resource {} and {}.".format(d, r.name, | ||
profile.name)) | ||
) | ||
|
||
except: | ||
raise exceptions.DataPackageException( | ||
( | ||
"Could not read resource {} from datpackage " | ||
"with name {}".format(r.name, p.descriptor['name']) | ||
) | ||
) | ||
print("Successfully tested datapackage {}.".format( | ||
p.descriptor['name'])) | ||
|
||
|
||
@click.group(chain=True) | ||
|
||
@click.pass_context | ||
def cli(ctx, **kwargs): | ||
ctx.obj = kwargs | ||
|
||
@cli.command() | ||
@click.argument("package", type=str, default="datapackage.json") | ||
@click.pass_context | ||
def test(ctx, package): | ||
_test(ctx, package) | ||
|
||
def main(): | ||
cli(obj={}) |
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.