mistree
mistree copied to clipboard
fixed ValueError for MST and fixed SnytaxErrors
- Fix Error for creating a MST in python greater than 3.7. in Branches.py the following error occurs:
File "~/mistree/mistree/mst/get_mst_class.py", line 198, in get_branches
branch_index, rejected_branch_index = branches.get_branch_index(self.edge_index, self.edge_degree)
File "~/mistree/mistree/mst/branches.py", line 86, in get_branch_index
branch_index.append(np.ndarray.tolist(np.ndarray.flatten(np.array(_twig))))
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (6,) + inhomogeneous part.
All pytest pass after change.
- Fixing SyntaxError for
is inandisto!=and==
hi @meyerls I'm just trying to understand the changes. The format change from mentions of is or is not to == and != looks fine, in fact I'm not sure why it was is before. Just to check was this throwing an error or is this just to get rid of this style? I need to better understand why you've added the [0]. I think I'm familiar with the error you're talking about, but I don't think this is something that breaks the code. Either way it will be good to get rid of it. I just need to make sure this doesn't cut off the array that we actually need. I'll take a look at this sometime next week.
hi @knaidoo29, i looked into it and tried it with python 3.5 and python 3.8. In py3.5 there seem to work everything fine with mistree v1.2.0. But in py3.8 it throws an error.
I cloud reduce the error to line 86 in branches.py. It is the call of np.array(_twig) where _twig is [0, array([1])]. In py3.5 this results into array([0, array([1])], dtype=object) and in py3.8 it throws a ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (6,) + inhomogeneous part..
I have not found any proper explanation (https://www.codingem.com/numpy-fix-valueerror-setting-array-element-with-sequence/). But i guess numpy has tightened its type checking rules.
Appending a [0] would access the integer under the assumption there will be only one value in the array.
Hi @knaidoo29, is there any update on this issue?
best regards, Lukas
Hi @meyerls, sorry for the delay, I needed to explore your solution a bit more in depth. I don't think taking the first element of the array is quite correct as this is often longer than just one element, since as I understand it this will mean we will lose some of the edges in the branches. I have reproduced this error, and you are right it is caused by stricter numpy usage of the array function. The solution which I think is best is to add dtype=object in the np.array functions. I've created a new version of mistree which has this now. Can you check that the new version also solves the issue you see. You can do this by just running 'pip install mistree' (version 1.2.2). Many thanks for flagging this issue.