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 index mismatch issue when passing a dataframe to the sankey function which has been sorted in any way #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

minoguep
Copy link

Hi there 👋

Two small changes here.

Noticed an issue when using this module the other day where if you pass a dataframe that has been sorted based on the weights, the output is incorrect (see example attached below). I did a bit of digging and I noticed that this is because you reindex left and right if they are passed as a series but not the leftWeight and rightWeight, so when you then create the dataFrame variable, there is in index mismatch and the values get jumbled up basically.

second thing I noticed is that when you check_data_matches_labelson the right hand side, you were actually passing in the leftLabels rather than the rightLabels which I think is incorrect.

Example

Sample dataset

left,right,weight
apple,apple, 2
apple,orange, 3
apple,banana,3
orange,apple,5
orange,orange,7
orange,banana,2
banana,apple,4
banana,orange,1
banana,banana,0

Create Sankey's

import pandas as pd 
from pySankey.sankey import sankey


data = pd.read_csv("sample_data.csv")


# Example 1: No reordering
sankey(
    left=data["left"], right=data["right"], 
    leftWeight=data["weight"], rightWeight=data["weight"], 
    aspect=20, fontsize=20
)


# Example 2: Some sorting applied (notice the difference in banana -> orange, and orange -> orange)
data_sorted = data.sort_values(by="weight")
sankey(
    left=data_sorted["left"], right=data_sorted["right"], 
    leftWeight=data_sorted["weight"], rightWeight=data_sorted["weight"], 
    aspect=20, fontsize=20
)

@Pierre-Sassoulas
Copy link
Contributor

This repo is not maintened or deploying new versions, you can open the PR in my fork if you want.

@minoguep
Copy link
Author

Thanks for the heads up, will do that now!

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.

3 participants