Пример #1
0
def test_get_display_value_self_describing_object():
    """Check that SelfDescribingObject is displayed correctly."""
    json_object = json.loads("{\"schema\" : \"Integer\", \"value\": 23}")
    assert _get_display_value('SelfDescribing', json_object) == 23

    json_object = json.loads("{\"schema\" : \"Integer\"}")
    assert _get_display_value('SelfDescribing', json_object) is None
Пример #2
0
    def __init__(self, dictionary):
        if "answerElements" not in dictionary:
            raise ValueError("Answer elements not found in dictionary")
        if len(dictionary["answerElements"]) == 0:
            raise ValueError("Empty answer elements list in dictionary")
        if "metadata" not in dictionary["answerElements"][0]:
            raise ValueError("TableMetadata not found in dictionary")
        super(TableAnswerElement, self).__init__(dictionary)
        answer_element = dictionary["answerElements"][0]
        self.metadata = TableMetadata(answer_element["metadata"]) \
            # type: TableMetadata

        self.rows = [Row(row) for row in answer_element.get("rows", [])] \
            # type: List[Row]

        # TODO: row exclusions
        # (https://github.com/batfish/pybatfish/issues/5)

        self.table_headers = self.metadata.get_column_names(
        )  # type: List[str]
        self.table_data = pandas.DataFrame.from_records(
            [[
                _get_display_value(cm.schema, row.get(cm.name))
                for cm in self.metadata.column_metadata
            ] for row in self.rows],
            columns=self.table_headers)
Пример #3
0
def _rows_to_frame(table_metadata, rows):
    # type: (TableMetadata, List[Row]) -> pandas.DataFrame
    return pandas.DataFrame.from_records(
        [[_get_display_value(cm.schema, row.get(cm.name)) for
          cm in table_metadata.column_metadata]
         for row in rows], columns=table_metadata.get_column_names())
Пример #4
0
def test_get_display_value_unknown_schema():
    """Check that Integer values are extracted correctly."""
    assert _get_display_value('bogus', None) is None
    json_object = json.loads("{\"foo\" : 23}")
    assert _get_display_value('bogus', json_object) == json_object
Пример #5
0
def test_get_display_value_integer():
    """Check that Integer values are extracted correctly."""
    assert _get_display_value('Integer', "0") == 0
    assert _get_display_value('Integer', 0) == 0
    assert _get_display_value('Integer', -1) == -1
    assert _get_display_value('Integer', "-1") == -1