How to deal with graphs without edges in graph classfication

I am using dgl.from_networkx() to build a weighted undirected graph. But some graphs has no edges , So I consider two situation:

           if len(edges) > 0:
                g.add_weighted_edges_from(edges)
                g = dgl.from_networkx(g, node_attrs=['x', 'weight'], edge_attrs=['weight'])
            else:
                g = dgl.from_networkx(g, node_attrs=['x', 'weight'])

when using batch_graph, I get the error :

Expect all edges[(’_N’, ‘_E’, ‘_N’)].data to have the same set of keys, but got dict_keys([‘weight’]) and dict_keys([]).

The example below seems to be working fine.

import dgl
import networkx as nx
import numpy as np

nx_g1 = nx.DiGraph()
nx_g1.add_nodes_from([0, 1, 2], x=np.zeros((3, 1)), weight=np.ones((3, 1)))
nx_g1.add_edge(1, 2, weight=np.ones((1, 1)))
g1 = dgl.from_networkx(nx_g1, node_attrs=['x', 'weight'], edge_attrs=['weight'])
nx_g2 = nx.DiGraph()
nx_g2.add_nodes_from([0, 1, 2], x=np.zeros((3, 1)), weight=np.ones((3, 1)))
g2 = dgl.from_networkx(nx_g2, node_attrs=['x', 'weight'])
bg = dgl.batch([g1, g2])