Skip to content

Commit

Permalink
Merge pull request #26 from zblz/report-format-version
Browse files Browse the repository at this point in the history
Write lens report format version to report and validate it on load
  • Loading branch information
zblz committed Aug 31, 2018
2 parents c3086ff + 5575194 commit 6ad9f79
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lens/summarise.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@ class EmptyDataFrameError(Exception):
pass


def _validate_report(report):
def _validate_report(report, schema_version):
"""Validates a dict report"""
report_schema_version = report.get('_schema_version')
if (report_schema_version is not None and
report_schema_version != schema_version):
raise LensSummaryError('The version of the report schema `{}` does '
'not match the schema version `{}` supported '
'by this version of lens {}.'.format(
report_schema_version,
schema_version,
__version__
))

columns = report['_columns']
column_props = report['column_properties']
num_cols = [col for col in columns if (column_props[col]['numeric'])]
Expand Down Expand Up @@ -60,11 +71,16 @@ class Summary(object):
in a Jupyter notebook.
"""
schema_version = 1

def __init__(self, report):
if not isinstance(report, dict):
raise TypeError('report argument must be a dict')

_validate_report(report)
if '_schema_version' not in report.keys():
report['_schema_version'] = self.schema_version

_validate_report(report, schema_version=self.schema_version)
self._report = report

@staticmethod
Expand Down

0 comments on commit 6ad9f79

Please sign in to comment.