Ejemplo n.º 1
0
    def test_hyperedges_direct_manual_shaping(self):

        h1 = graphistry.hypergraph(hyper_df, verbose=False, direct=True, opts={'EDGES': {'aa': ['cc'], 'cc': ['cc']}})
        self.assertEqual(len(h1['edges']), 6)

        h2 = graphistry.hypergraph(hyper_df, verbose=False, direct=True, opts={'EDGES': {'aa': ['cc', 'bb', 'aa'], 'cc': ['cc']}})
        self.assertEqual(len(h2['edges']), 12)
Ejemplo n.º 2
0
    def test_skip_na_hyperedge(self, mock_open):

        nans_df = pd.DataFrame({'x': ['a', 'b', 'c'], 'y': ['aa', None, 'cc']})
        expected_hits = ['a', 'b', 'c', 'aa', 'cc']

        skip_attr_h_edges = graphistry.hypergraph(
            nans_df, drop_edge_attrs=True)['edges']
        self.assertEqual(len(skip_attr_h_edges), len(expected_hits))

        default_h_edges = graphistry.hypergraph(nans_df)['edges']
        self.assertEqual(len(default_h_edges), len(expected_hits))
Ejemplo n.º 3
0
    def test_drop_edge_attrs_direct(self):
        
        h = graphistry.hypergraph(triangleNodes,
            ['id', 'a1', '🙈'],
            verbose=False, direct=True, drop_edge_attrs=True,
            opts = {
                'EDGES': {
                    'id': ['a1'],
                    'a1': ['🙈']
                }
            })

        logger.debug('h.nodes: %s', h['graph']._nodes)
        logger.debug('h.edges: %s', h['graph']._edges)

        self.assertEqual(len(h.keys()), len(['entities', 'nodes', 'edges', 'events', 'graph']))

        edges = pd.DataFrame({
            'edgeType': ['a1::🙈', 'a1::🙈', 'a1::🙈', 'id::a1', 'id::a1', 'id::a1'],
            'src': [
                'a1::1', 'a1::2', 'a1::3',
                'id::a', 'id::b', 'id::c'],
            'dst': [
                '🙈::æski ēˈmōjē', '🙈::😋', '🙈::s',
                'a1::1', 'a1::2', 'a1::3'],
            'EventID': [
                'EventID::0', 'EventID::1', 'EventID::2',
                'EventID::0', 'EventID::1', 'EventID::2']})

        assertFrameEqual(h['edges'], edges)
        for (k, v) in [('entities', 9), ('nodes', 9), ('edges', 6), ('events', 0)]:
            logger.error('testing: %s', k)
            logger.error('actual: %s', h[k])
            self.assertEqual(len(h[k]), v)
Ejemplo n.º 4
0
    def test_simple(self, mock_open):

        h = graphistry.hypergraph(triangleNodes, verbose=False)

        self.assertEqual(
            len(h.keys()),
            len(['entities', 'nodes', 'edges', 'events', 'graph']))

        edges = pd.DataFrame({
            'edgeType': [
                'a1', 'a1', 'a1', 'a2', 'a2', 'a2', 'a6', 'a6', 'a6', 'id',
                'id', 'id'
            ],
            'attribID': [
                'a1::1', 'a1::2', 'a1::3', 'a2::red', 'a2::blue', 'a2::green',
                'a6::æski ēˈmōjē', 'a6::😋', 'a6::s', 'id::a', 'id::b', 'id::c'
            ],
            'EventID': [
                'EventID::0', 'EventID::1', 'EventID::2', 'EventID::0',
                'EventID::1', 'EventID::2', 'EventID::0', 'EventID::1',
                'EventID::2', 'EventID::0', 'EventID::1', 'EventID::2'
            ]
        })

        assertFrameEqual(h['edges'], edges)
        for (k, v) in [('entities', 12), ('nodes', 15), ('edges', 12),
                       ('events', 3)]:
            self.assertEqual(len(h[k]), v)
Ejemplo n.º 5
0
    def test_hyperedges(self):

        h = graphistry.hypergraph(triangleNodes, verbose=False)

        self.assertEqual(
            len(h.keys()),
            len(['entities', 'nodes', 'edges', 'events', 'graph']))

        edges = pd.DataFrame({
            'a1': [1, 2, 3] * 4,
            'a2': ['red', 'blue', 'green'] * 4,
            'id': ['a', 'b', 'c'] * 4,
            '🙈': ['æski ēˈmōjē', '😋', 's'] * 4,
            'edgeType': [
                'a1', 'a1', 'a1', 'a2', 'a2', 'a2', 'id', 'id', 'id', '🙈', '🙈',
                '🙈'
            ],
            'attribID': [
                'a1::1', 'a1::2', 'a1::3', 'a2::red', 'a2::blue', 'a2::green',
                'id::a', 'id::b', 'id::c', '🙈::æski ēˈmōjē', '🙈::😋', '🙈::s'
            ],
            'EventID': [
                'EventID::0', 'EventID::1', 'EventID::2', 'EventID::0',
                'EventID::1', 'EventID::2', 'EventID::0', 'EventID::1',
                'EventID::2', 'EventID::0', 'EventID::1', 'EventID::2'
            ]
        })

        assertFrameEqual(h['edges'], edges)
        for (k, v) in [('entities', 12), ('nodes', 15), ('edges', 12),
                       ('events', 3)]:
            self.assertEqual(len(h[k]), v)
Ejemplo n.º 6
0
    def test_drop_edge_attrs(self):

        h = graphistry.hypergraph(triangleNodes, ['id', 'a1', '🙈'],
                                  verbose=False,
                                  drop_edge_attrs=True)

        self.assertEqual(
            len(h.keys()),
            len(['entities', 'nodes', 'edges', 'events', 'graph']))

        edges = pd.DataFrame({
            'edgeType': ['a1', 'a1', 'a1', 'id', 'id', 'id', '🙈', '🙈', '🙈'],
            'attribID': [
                'a1::1', 'a1::2', 'a1::3', 'id::a', 'id::b', 'id::c',
                '🙈::æski ēˈmōjē', '🙈::😋', '🙈::s'
            ],
            'EventID': [
                'EventID::0', 'EventID::1', 'EventID::2', 'EventID::0',
                'EventID::1', 'EventID::2', 'EventID::0', 'EventID::1',
                'EventID::2'
            ]
        })

        assertFrameEqual(h['edges'], edges)
        for (k, v) in [('entities', 9), ('nodes', 12), ('edges', 9),
                       ('events', 3)]:
            self.assertEqual(len(h[k]), v)
Ejemplo n.º 7
0
 def test_hyper_to_pa_all_direct(self):
     hg = graphistry.hypergraph(triangleNodes, ['id', 'a1', '🙈'], direct=True)
     nodes_arr = pa.Table.from_pandas(hg['graph']._nodes)
     assert len(hg['graph']._nodes) == 9
     assert len(nodes_arr) == 9
     edges_err = pa.Table.from_pandas(hg['graph']._edges)
     assert len(hg['graph']._edges) == 9
     assert len(edges_err) == 9
Ejemplo n.º 8
0
    def test_drop_na_direct(self):

        df = pd.DataFrame({'a': ['a', None, 'a'], 'i': [1, 1, None]})

        hg = graphistry.hypergraph(df, drop_na=True, direct=True)

        assert len(hg['graph']._nodes) == 2
        assert len(hg['graph']._edges) == 1
Ejemplo n.º 9
0
    def test_drop_na_hyper(self):

        df = pd.DataFrame({'a': ['a', None, 'c'], 'i': [1, 2, None]})

        hg = graphistry.hypergraph(df, drop_na=True)

        assert len(hg['graph']._nodes) == 7
        assert len(hg['graph']._edges) == 4
Ejemplo n.º 10
0
    def test_hyper_to_pa_mixed(self):

        df = pd.DataFrame({'x': ['a', 'b', 'c'], 'y': [1, 2, 3]})

        hg = graphistry.hypergraph(df)
        nodes_arr = pa.Table.from_pandas(hg['graph']._nodes)
        assert len(nodes_arr) == 9
        edges_err = pa.Table.from_pandas(hg['graph']._edges)
        assert len(edges_err) == 6
Ejemplo n.º 11
0
    def test_hyper_to_pa_na(self):

        df = pd.DataFrame({'x': ['a', None, 'c'], 'y': [1, 2, None]})

        hg = graphistry.hypergraph(df, drop_na=False)
        nodes_arr = pa.Table.from_pandas(hg['graph']._nodes)
        assert len(hg['graph']._nodes) == 9
        assert len(nodes_arr) == 9
        edges_err = pa.Table.from_pandas(hg['graph']._edges)
        assert len(hg['graph']._edges) == 6
        assert len(edges_err) == 6
Ejemplo n.º 12
0
    def test_hyperedges_direct_categories(self, mock_open):

        h = graphistry.hypergraph(
            hyper_df,
            verbose=False,
            direct=True,
            opts={'CATEGORIES': {
                'n': ['aa', 'bb', 'cc']
            }})

        self.assertEqual(len(h['edges']), 9)
        self.assertEqual(len(h['nodes']), 6)
Ejemplo n.º 13
0
    def test_hyperedges_direct(self):

        h = graphistry.hypergraph(hyper_df, verbose=False, direct=True)
        
        self.assertEqual(len(h['edges']), 9)
        self.assertEqual(len(h['nodes']), 9)
Ejemplo n.º 14
0
 def test_hyper_evil(self):
     graphistry.hypergraph(squareEvil)
Ejemplo n.º 15
0
 def test_hyper_evil(self, mock_open):
     graphistry.hypergraph(squareEvil)