cytoscape / ipycytoscape

A Cytoscape Jupyter widget
https://ipycytoscape.readthedocs.io/en/master/
BSD 3-Clause "New" or "Revised" License
269 stars 62 forks source link

Adding example with pandas. A different approach #231

Closed joseberlines closed 3 years ago

joseberlines commented 3 years ago

Hi @marimeireles, Hi @ianhi I PR adding a new example file that illustrates an alternative use of pandas for manipulating the graphs resulting with ipycytoscape.

When I have time and find the way it is my intention to PR the method into the source code of ipycytoscape.

joseberlines commented 3 years ago

I just realise now there are some problems in this note book. I will have a look.

joseberlines commented 3 years ago

I just dont understand what are the tests Falling in this file.

marimeireles commented 3 years ago

Hey @joseberlines, sorry I'm not super present around... I'm trying to finish another review and once I do I'll get back to this PR :) Thank you for the contributions! :cherry_blossom: It's really super appreciated, sorry for the lack of time here.

marimeireles commented 3 years ago

Hey @joseberlines, thank you for the contribution :) So the way our test system is working currently is: it's grabbing the notebooks we have on our example folder and running all of them. I don't know much about the internals of this, but investigating your PR further I found that this behavior is changing depending on which cells you've previously executed.

I'm going to create a contributing.md file to document some pitfalls we might get into while contributing. But one thing that fixed most bugs was actually restarting and cleaning the notebook:

image

We should always have [ ] empty execution cells.

Now we actually have one error in the code itself:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-f1cd00616845> in <module>
----> 1 stations_df['background-color'] = stations_df['id'].apply(lambda x: 'violet' if x in list_of_HS_stations and x is not None else 'yellow')

~/miniconda3/envs/ipycytoscape/lib/python3.9/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
   4136             else:
   4137                 values = self.astype(object)._values
-> 4138                 mapped = lib.map_infer(values, f, convert=convert_dtype)
   4139 
   4140         if len(mapped) and isinstance(mapped[0], Series):

pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()

<ipython-input-13-f1cd00616845> in <lambda>(x)
----> 1 stations_df['background-color'] = stations_df['id'].apply(lambda x: 'violet' if x in list_of_HS_stations and x is not None else 'yellow')

TypeError: argument of type 'NoneType' is not iterable

I'll mark it in a review.

joseberlines commented 3 years ago

Thanks to both. Indeed I did not think for a second about cleanibg the outputs. I will have a look. If you want I can tr a new PR and discjarge this one.

marimeireles commented 3 years ago

@joseberlines you choose! :) either way is fine.

marimeireles commented 3 years ago

Closing because #245 contains #231