Skip to content

Commit

Permalink
fix np array np.int64 conversion for python3
Browse files Browse the repository at this point in the history
  • Loading branch information
wweir827 committed Jun 15, 2018
1 parent fb7b9db commit 9762b75
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/VertexPartition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from . import _c_louvain
from .functions import _get_py_capsule
import sys
import numpy as np
# Check if working with Python 3
PY3 = (sys.version > '3')

Expand Down Expand Up @@ -849,8 +850,15 @@ def __init__(self, graph, layer_vec=None, initial_membership=None, weights=None,
else:
# Make sure it is a list
weights = list(weights)


if layer_vec is not None:
layer_vec = list(layer_vec) # ensure that it is a list
layer_vec=np.array(layer_vec).tolist()
# if isinstance(layer_vec, np.ndarray):
# layer_vec = layer_vec.tolist()
# elif layer_vec is not None:
# layer_vec = list(layer_vec)

else:
layer_vec = [0 for _ in range(graph.vcount())] #default is to assume single layer

Expand Down

4 comments on commit 9762b75

@vtraag
Copy link
Owner

@vtraag vtraag commented on 9762b75 Jun 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be better to recode the C API to use the iterator approach (which should work on all iterable input), rather than introducing a dependency on numpy.

@wweir827
Copy link
Author

@wweir827 wweir827 commented on 9762b75 Jun 15, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vtraag
Copy link
Owner

@vtraag vtraag commented on 9762b75 Jun 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I thought it was a problem with the iteration. In that case I would simply convert it to a python list with python types on your external code, rather than integrating this conversion in the package.

@vtraag
Copy link
Owner

@vtraag vtraag commented on 9762b75 Jun 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this issue should be dealt with in a different way for python3, see also numpy/numpy#2951. I think this should work https://docs.python.org/3/c-api/number.html#c.PyNumber_AsSsize_t

Please sign in to comment.