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

TypeError: 'method' object is not subscriptable #135

Open
LeonHardwolscht opened this issue May 6, 2024 · 0 comments
Open

TypeError: 'method' object is not subscriptable #135

LeonHardwolscht opened this issue May 6, 2024 · 0 comments

Comments

@LeonHardwolscht
Copy link

Hi,
I just learnt about floweaver and started a small tutorial within my venv on Python 3.12.2 to get to know the package. However, when I run the code provided below, it raises me a TypeError.

This is my example code:

from floweaver import *
import pandas as pd


flows = pd.DataFrame([
    {'source': 'farm1', 'target': 'Mary', 'value': 3, 'type': 'apples'},
    {'source': 'farm1', 'target': 'James', 'value': 1, 'type': 'apples'},
    {'source': 'farm2', 'target': 'Fred', 'value': 4, 'type': 'apples'},
    {'source': 'farm2', 'target': 'Fred', 'value': 4, 'type': 'bananas'},
    {'source': 'farm2', 'target': 'Susan', 'value': 4, 'type': 'bananas'},
    {'source': 'farm3', 'target': 'Susan', 'value': 4, 'type': 'apples'},
    {'source': 'farm4', 'target': 'Susan', 'value': 4, 'type': 'bananas'},
    {'source': 'farm5', 'target': 'Susan', 'value': 4, 'type': 'bananas'},
    {'source': 'farm6', 'target': 'Susan', 'value': 4, 'type': 'bananas'},
], columns=['source', 'target', 'value', 'type'])

# Set the default size to fit the documentation better.
size = dict(width=570, height=300)

nodes = {
    'farms': ProcessGroup(['farm1', 'farm2', 'farm3',
                           'farm4', 'farm5', 'farm6']),
    'customers': ProcessGroup(['James', 'Mary', 'Fred', 'Susan']),
}
ordering = [
    ['farms'],       # put "farms" on the left...
    ['customers'],   # ... and "customers" on the right.
]
bundles = [
    Bundle('farms', 'customers'),
]
sdd = SankeyDefinition(nodes, bundles, ordering)
weave(sdd, flows).to_widget(**size)

raising the following error message:

TypeError                                 Traceback (most recent call last)
Cell In[6], [line 33]
     [29] bundles = [
     [30] Bundle('farms', 'customers'),
     [31] ]
     [32] sdd = SankeyDefinition(nodes, bundles, ordering)
---> [33] weave(sdd, flows).to_widget(**size)

File \.venv\Lib\site-packages\floweaver\weave.py:36, in weave(sankey_definition, dataset, measures, link_width, link_color, palette, add_elsewhere_waypoints)
     [33](file:/.venv/Lib/site-packages/floweaver/weave.py:33)     dataset = Dataset(dataset)
     [35](file:/.venv/Lib/site-packages/floweaver/weave.py:35) # Calculate the view graph (adding dummy nodes)
---> [36](file:/.venv/Lib/site-packages/floweaver/weave.py:36) GV = view_graph(sankey_definition)
     [38](file:/.venv/Lib/site-packages/floweaver/weave.py:38) # Add implicit to/from Elsewhere bundles to the view definition to ensure
     [39](file:/.venv/Lib/site-packages/floweaver/weave.py:39) # consistency.
     [40](file:/.venv/Lib/site-packages/floweaver/weave.py:40) new_waypoints, new_bundles = elsewhere_bundles(sankey_definition, add_elsewhere_waypoints)

File \.venv\Lib\site-packages\floweaver\view_graph.py:14, in view_graph(sankey_definition)
     [11](file:/.venv/Lib/site-packages/floweaver/view_graph.py:11)     G.add_node(k, node=node)
     [13](file:/.venv/Lib/site-packages/floweaver/view_graph.py:13) G.ordering = sankey_definition.ordering
---> [14](file:/.venv/Lib/site-packages/floweaver/view_graph.py:14) G = _add_bundles_to_graph(G, sankey_definition.bundles,
     [15](file:/.venv/Lib/site-packages/floweaver/view_graph.py:15)                           _bundle_order(sankey_definition))
     [17](file:/.venv/Lib/site-packages/floweaver/view_graph.py:17) return G

File \.venv\Lib\site-packages\floweaver\view_graph.py:32, in _add_bundles_to_graph(G, bundles, sort_key)
...
     [20](file:/.venv/Lib/site-packages/floweaver/layered_graph.py:20) def get_node(self, u):
     [21](file:/.venv/Lib/site-packages/floweaver/layered_graph.py:21)     """Get the ProcessGroup or Waypoint associated with `u`"""
---> [22](file:/.venv/Lib/site-packages/floweaver/layered_graph.py:22)     return self.nodes[u]['node']

TypeError: 'method' object is not subscriptable

I'm using floweaver 2.0.1 with
numpy 1.26.4
pandas 2.2.1
networkx 3.3
attrs 23.2.0

Can you please help me to employ the package?

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

No branches or pull requests

1 participant