Skip to content

Commit

Permalink
[Lint] Pylint (#330)
Browse files Browse the repository at this point in the history
* fix lint for graph_index.py

* pylint for base.py

* pylint for batched_graph.py

* pylint for frame.py; simplify and fix bugs in frame when index is slice type

* pylint for graph.py

* pylint for immutable_graph_index.py

* pylint for init.py

* pylint for rest files in root package

* pylint for _ffi package

* pylint for function package

* pylint for runtime package

* pylint for runtime.ir package

* add pylint to ci

* fix mx tests

* fix lint errors

* fix ci

* fix as requested

* fix lint
  • Loading branch information
jermainewang authored Jan 1, 2019
1 parent 1e50cd2 commit 4bd4d6e
Show file tree
Hide file tree
Showing 40 changed files with 1,857 additions and 655 deletions.
4 changes: 1 addition & 3 deletions python/dgl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# One has to manually import dgl.data; fixes #125
#from . import data
"""DGL root package."""
from . import function
from . import nn
from . import contrib
Expand All @@ -12,7 +11,6 @@
from .backend import load_backend
from .batched_graph import *
from .graph import DGLGraph
from .subgraph import DGLSubGraph
from .traversal import *
from .propagate import *
from .udf import NodeBatch, EdgeBatch
1 change: 1 addition & 0 deletions python/dgl/_api_internal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Namespace for internal apis."""
3 changes: 1 addition & 2 deletions python/dgl/_ffi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

class DGLError(Exception):
"""Error thrown by DGL function"""
pass

pass # pylint: disable=unnecessary-pass

def _load_lib():
"""Load libary by searching possible path."""
Expand Down
2 changes: 1 addition & 1 deletion python/dgl/_ffi/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Function(_FunctionBase):
dgl.register_func: How to register global function.
dgl.get_global_func: How to get global function.
"""
pass
pass # pylint: disable=unnecessary-pass


class ModuleBase(object):
Expand Down
2 changes: 1 addition & 1 deletion python/dgl/_ffi/runtime_ctypes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Common runtime ctypes."""
# pylint: disable=invalid-name
# pylint: disable=invalid-name, super-init-not-called
from __future__ import absolute_import

import ctypes
Expand Down
25 changes: 25 additions & 0 deletions python/dgl/backend/mxnet/immutable_graph_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,31 @@ def from_coo_matrix(self, out_coo):
self.__init__(mx.nd.sparse.csr_matrix((edge_ids, (dst, src)), shape=(size, size)).astype(np.int64),
mx.nd.sparse.csr_matrix((edge_ids, (src, dst)), shape=(size, size)).astype(np.int64))

def from_edge_list(self, elist):
"""Convert from an edge list.
Paramters
---------
elist : list
List of (u, v) edge tuple.
"""
src, dst = zip(*elist)
src = np.array(src)
dst = np.array(dst)
num_nodes = max(src.max(), dst.max()) + 1
min_nodes = min(src.min(), dst.min())
if min_nodes != 0:
raise DGLError('Invalid edge list. Nodes must start from 0.')
edge_ids = mx.nd.arange(0, len(src), step=1, repeat=1, dtype=np.int32)
src = mx.nd.array(src, dtype=np.int64)
dst = mx.nd.array(dst, dtype=np.int64)
# TODO we can't generate a csr_matrix with np.int64 directly.
in_csr = mx.nd.sparse.csr_matrix((edge_ids, (dst, src)),
shape=(num_nodes, num_nodes)).astype(np.int64)
out_csr = mx.nd.sparse.csr_matrix((edge_ids, (src, dst)),
shape=(num_nodes, num_nodes)).astype(np.int64)
self.__init__(in_csr, out_csr)

def create_immutable_graph_index(in_csr=None, out_csr=None):
""" Create an empty backend-specific immutable graph index.
Expand Down
9 changes: 6 additions & 3 deletions python/dgl/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

import warnings

from ._ffi.base import DGLError
from ._ffi.base import DGLError # pylint: disable=unused-import

# A special argument for selecting all nodes/edges.
# A special symbol for selecting all nodes or edges.
ALL = "__ALL__"

def is_all(arg):
"""Return true if the argument is a special symbol for all nodes or edges."""
return isinstance(arg, str) and arg == ALL

dgl_warning = warnings.warn
def dgl_warning(msg):
"""Print out warning messages."""
warnings.warn(msg)
Loading

0 comments on commit 4bd4d6e

Please sign in to comment.