By Developers, For Developers

Historical errata for Complex Network Analysis in Python

PDF PgPaper PgTypeDescriptionFixed onComments
18ERROR

Table 2 lists iGraph as having OpenMP support and graph-tool as not having that support. The text (p16) states that graph-tool is the one with OpenMP support.

2017-10-23
25TYPO

At the bottom of page 25, in the G.add_nodes and G.add_nodes_from examples, eadible should be edible.

2017-11-08
27ERROR

Trying to execute nutrients.py example, I got the following error (networkx 2.0 installed).
Could help me please ?

D:\\DEV\\Python36-32\\python.exe “C:/Users/Laurent2/Documents/DOC/Informatique/IA/ML Python/dzcnapy-code/code/nutrients.py”
[‘A’, ‘carrots’, ‘eggs’, ‘fatty fish’, ‘green leafy vegs’, ‘liver’, ‘milk’, ‘tomatoes’, ‘B12’, ‘B6’, ‘asparagus’, ‘beans’, ‘kidneys’, ‘potatoes’, ‘C’, ‘pumpkins’, ‘Ca’, ‘broccoli’, ‘cheese’, ‘Cu’, ‘nuts’, ‘whole grains’, ‘D’, ‘mushrooms’, ‘E’, ‘seeds’, ‘Mn’, ‘legumes’, ‘wheat’, ‘Se’, ‘Zn’, ‘beef’, ‘riboflavin’, ‘niacin’, ‘folates’, ‘spinach’, ‘poultry’, ‘shellfish’, ‘thiamin’, ‘veg oils’, ‘yogurt’]
<generator object selfloop_edges.. at 0x0ECCC2D0>
Traceback (most recent call last):
File “D:\\DEV\\Python36-32\\lib\\site-packages\
etworkx\\classes\\function.py”, line 641, in set_node_attributes
for n, v in values.items():
AttributeError: ‘str’ object has no attribute ‘items’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:/Users/Laurent2/Documents/DOC/Informatique/IA/ML Python/dzcnapy-code/code/nutrients.py”, line 25, in
nx.set_node_attributes(G, “nutrient”, nutrient_dict)
File “D:\\DEV\\Python36-32\\lib\\site-packages\
etworkx\\classes\\function.py”, line 648, in set_node_attributes
G.nodes[n][name] = values
TypeError: unhashable type: ‘dict’
[‘A’, ‘B12’, ‘B6’, ‘C’, ‘Ca’, ‘Cu’, ‘D’, ‘E’, ‘Mn’, ‘Se’, ‘Zn’, ‘Carrots’, ‘Eggs’, ‘Fatty Fish’, ‘Green Leafy Vegs’, ‘Liver’, ‘Milk’, ‘Tomatoes’, ‘Asparagus’, ‘Beans’, ‘Kidneys’, ‘Potatoes’, ‘Pumpkins’, ‘Broccoli’, ‘Cheese’, ‘Nuts’, ‘Whole Grains’, ‘Mushrooms’, ‘Seeds’, ‘Legumes’, ‘Wheat’, ‘Beef’, ‘Riboflavin’, ‘Niacin’, ‘Folates’, ‘Spinach’, ‘Poultry’, ‘Shellfish’, ‘Thiamin’, ‘Veg Oils’, ‘Yogurt’]

Process finished with exit code 1

2017-12-07You must be using networkx 2.0. The book uses 1.11.
27ERROR

the code below failed with networkx 2.0 as I write in my previous erratum message
nx.set_node_attributes(G, “nutrient”, nutrient_dict)

but the one below run well :
nx.set_node_attributes(G, nutrient_dict, “nutrient”)

2017-12-07You must be using networkx 2.0. The book uses 1.11.
218ERROR

In the for loop of the code example for graph_tool, should zip(nodes, names) be zip(nodes, labels)?

2017-12-24Thank you ! Will fix.
42ERROR

nx.set_node_attributes(G, “nutrient”, nutrient_dict) # does not work
nx.set_node_attributes(G, nutrient_dict, “nutrient”) # does work

2018-01-09You must be using networkx 2.0. The book uses 1.11.
4429ERROR

colors = [“yellow” if n[1][‘nutrient’] else “pink” for n in G.nodes(data=True)] # should be…
colors = [“yellow” if n[1][‘nutrients’] else “pink” for n in G.nodes(data=True)]

2018-01-09The attribute name, as set on line 32 of the file, is 'nutrient', not 'nutrients'.
4429SUGGEST

You need to be clearer about how to run the code. People are (probably) copying what you’ve typed in the book.
dzcnapy.medium_attrs[“node_color”] = colors is not going to work, because you need to run the dzcnapy_plotlib.py code first. Something like: exec(open (“./dzcnapy_plotlib.py”).read()) will get them started…
…then people can step through the lines of nutrients.py, which is what you’ve put into the book’s text.

2018-01-09There is a "import dzcnapy_plotlib as dzcnapy" at the beginning of the file, it takes care of all imports.
6552ERROR

items() method is not available on this call
(maybe networkx has changed - I’m running Anaconda 3.6)
[wiki2net.py]
>>> core = [node for node, deg in F.degree().items() if deg >= 2]
Traceback (most recent call last):
File “”, line 1, in
AttributeError: ‘DiDegreeView’ object has no attribute ‘items’

>>> dir(core)
[‘add’, ‘class’, ‘contains’, ‘delattr’, ‘delitem’, ‘dir’, ‘doc’, ‘eq’, ‘format’, ‘ge’, ‘getattribute’, ‘getitem’, ‘gt’, ‘hash’, ‘iadd’, ‘imul’, ‘init’, ‘init_subclass’, ‘iter’, ‘le’, ‘len’, ‘lt’, ‘mul’, ‘ne’, ‘new’, ‘reduce’, ‘reduce_ex’, ‘repr’, ‘reversed’, ‘rmul’, ‘setattr’, ‘setitem’, ‘sizeof’, ‘str’, ‘subclasshook’, ‘append’, ‘clear’, ‘copy’, ‘count’, ‘extend’, ‘index’, ‘insert’, ‘pop’, ‘remove’, ‘reverse’, ‘sort’]

2018-01-09You must be using networkx 2.0. The book uses 1.11.
6552ERROR

This is a correction/clarification to #82471
Of course, I should be documenting the type, of F - not of core, to show that method items() does not exist:

>>>print(dir(F))
[‘class’, ‘contains’, ‘delattr’, ‘dict’, ‘dir’, ‘doc’, ‘eq’, ‘format’, ‘ge’, ‘getattribute’, ‘getitem’, ‘getstate’, ‘gt’, ‘hash’, ‘init’, ‘init_subclass’, ‘iter’, ‘le’, ‘len’, ‘lt’, ‘module’, ‘ne’, ‘new’, ‘reduce’, ‘reduce_ex’, ‘repr’, ‘setattr’, ‘sizeof’, ‘str’, ‘subclasshook’, ‘weakref’, ‘_adj’, ‘_node’, ‘_pred’, ‘_succ’, ‘add_cycle’, ‘add_edge’, ‘add_edges_from’, ‘add_node’, ‘add_nodes_from’, ‘add_path’, ‘add_star’, ‘add_weighted_edges_from’, ‘adj’, ‘adjacency’, ‘adjlist_inner_dict_factory’, ‘adjlist_outer_dict_factory’, ‘clear’, ‘copy’, ‘degree’, ‘edge_attr_dict_factory’, ‘edge_subgraph’, ‘edges’, ‘fresh_copy’, ‘get_edge_data’, ‘graph’, ‘has_edge’, ‘has_node’, ‘has_predecessor’, ‘has_successor’, ‘in_degree’, ‘in_edges’, ‘is_directed’, ‘is_multigraph’, ‘name’, ‘nbunch_iter’, ‘neighbors’, ‘node’, ‘node_dict_factory’, ‘nodes’, ‘nodes_with_selfloops’, ‘number_of_edges’, ‘number_of_nodes’, ‘number_of_selfloops’, ‘order’, ‘out_degree’, ‘out_edges’, ‘pred’, ‘predecessors’, ‘remove_edge’, ‘remove_edges_from’, ‘remove_node’, ‘remove_nodes_from’, ‘reverse’, ‘root_graph’, ‘selfloop_edges’, ‘size’, ‘subgraph’, ‘succ’, ‘successors’, ‘to_directed’, ‘to_undirected’]

2018-01-09
7865TYPO

Cristiano Ronaldo is Portuguese (from Madeira), and not Brazilian.
[There was a footballer called Ronaldo from Brazil, but it’s not the same person]

2018-01-15Shame on me!
95ERROR

Apparently, G.node does not return a dictionary, but just a list. Hence, print(G.node) displays:
[‘A’, ‘eggs’, ‘spinach’, ‘folates’, ‘asparagus’, ‘liver’, ‘Se’]

The same with print(G.edges), that displays:
[(‘A’, ‘eggs’), (‘spinach’, ‘folates’), (‘folates’, ‘liver’), (‘folates’, ‘asparagus’), (‘liver’, ‘Se’)]

Moreover print(G.edge), as reported in the book, does return an error message.

2018-01-17You must be using networkx 2.0. The book is using networkx 1.11.
101ERROR

(tested on mac os, with python 3.6.3)
Code below probably needs to be fixed:
loops = G.selfloop_edges()
​G.remove_edges_from(loops)
​​ print​(loops)

First observation: loops is a generator expression, and it cannot be printed directly. We need to use list function or * (e.g. print(*loops) or print(list(loops)).
However, this printing will make the cursor over the iterator to run until the end of the list. So if you execute immediately after the following instruction:
G.remove_edges_from(loops)
you are passing an empty list to remove_edges_from function and no edges will be removed from the graph.

2018-01-17You must be using networkx 2.0. The book is using networkx 1.11.
108ERROR

The following instruction misuses the parameters order:

nx.set_node_attributes(G, ​“nutrient”​, nutrient_dict)

Instead, tt should be called as it follows:

nx.set_node_attributes(G, nutrient_dict, ​“nutrient”​)

2018-01-17You must be using networkx 2.0. The book is using networkx 1.11.
46ERROR

Not fixed promised in B2
—————————————————————————————————————-
AttributeError Traceback (most recent call last)
in ()
——> 1 core = [node for node, deg in F.degree().items() if deg >= 2]
2 G = nx.subgraph(F, core)
3 print(“{} nodes, {} edges”.format(len(G), nx.number_of_edges(G)))
4 # 2995 nodes, 11817 edges
5 nx.write_graphml(G, “cna.graphml”)

AttributeError: ‘DiDegreeView’ object has no attribute ‘items’

2018-05-03
46SUGGEST

I downgraded to 1.11 and it works. Please let us know if there is a fix for networkx 2.X for this so that we can upgrade from 1.11. Thanks.

AttributeError Traceback (most recent call last)
in ()
——> 1 core = [node for node, deg in F.degree().items() if deg >= 2]
2 G = nx.subgraph(F, core)
3 print(“{} nodes, {} edges”.format(len(G), nx.number_of_edges(G)))
4 # 2995 nodes, 11817 edges
5 nx.write_graphml(G, “cna.graphml”)

AttributeError: ‘DiDegreeView’ object has no attribute ‘items’

2018-05-03
12.6%SUGGEST

12.6% of the epub file (Part 1, Construct a Simple Network with NetworkX), in the following sentence:

“Being the father of” is a symmetric relationship and would be represented by a directed edge.

shouldn’t it be an assymmetric relationship?

2018-05-03
1ERROR

ToC in EPUB format does not include chapter names and it is flat; specifically, while reading on a Nook. ToC is hierarchical in other PragProg books on the same device.

6347TYPO

In ‘Thou Should Not Have Contracted Self-Loops’ box (line 4), the word ‘loder’ should be ‘older’.

206201ERROR

When using the migrations.py code I am running into the error stating —

AttributeError: module ‘networkx’ has no attribute ‘from_pandas_edgelist’

I’m entering it into github too but hoping that you see this, perhaps can give me some guidance.

The latest version of the book uses networkx 2.0 or later. You must be using networkx 1.1 which indeed does not have 'from_pandas_edgelist'.
47TYPO

In the “Thou Should Not Have Contracted Self-Loops”, it says “If you use an loder version” rather than “If you use an older version”

5149ERROR

Should,

print(nx.topological_sort(G)[::–1])

be

print(list(reversed(list(nx.topological_sort(G)))))

in “adjectives.py”?

103SUGGEST

The csv files for the panama papers case study are not included in the source code folder.

1-233SUGGEST

Book uses old version of software library, author uses an updated software library to describe to paying customers how said technology should work. Pragmatic Bookshelf collects money from people that believed books describing software purchased actually work. Not buying any books from Pragmatic Programmers again.

Categories: