Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed ValueError for MST and fixed SnytaxErrors #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

meyerls
Copy link

@meyerls meyerls commented Mar 31, 2023

  • 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 in and is to != and ==

@knaidoo29
Copy link
Owner

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.

@meyerls
Copy link
Author

meyerls commented Mar 31, 2023

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.

@meyerls
Copy link
Author

meyerls commented Jul 7, 2023

Hi @knaidoo29,
is there any update on this issue?

best regards,
Lukas

@knaidoo29
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants