You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>The <code>find_first</code> function finds the first occurrence of an element in a list (or an array) of elements and returns its index. The <code>check_data</code> function uses this function to find a certain value in the data and prints the data until that point. It uses some fake “data” and takes an <code>target</code> argument to specify what value to look for.</p>
72
72
<p>If we run the <code>check_data</code> function, all looks fine:</p>
20 print('Data until first occurrence of', target, ':', test_data[:index])
126
126
ipdb> test_data
127
-
[3, 2, 8, 9, 3, 4, 7, 5]</code></pre>
127
+
[3, 2, 8, 9, 3, nan, 4, 7, 5]</code></pre>
128
128
<p>To get back to where we were before, we use <code>down</code> or alternatively <code>d</code> (instead of <code>up</code> we can also use <code>u</code>):</p>
<p>Using a counter and indexing into a list at every iteration of a loop is a often considered to be a so-called “<ahref="https://en.wikipedia.org/wiki/Anti-pattern">anti-pattern</a>” in Python.</p>
150
150
<asideclass="callout panel panel-info">
151
151
<divclass="panel-heading">
152
-
<h2><spanclass="glyphicon glyphicon-pushpin"></span>Post-mortem debugging with pytest</h2>
152
+
<h2id="post-mortem-debugging-with-pytest"><spanclass="glyphicon glyphicon-pushpin"></span>Post-mortem debugging with pytest</h2>
153
153
</div>
154
154
<divclass="panel-body">
155
155
<p>You can run your test suite with pytest and make pytest open a debugger session for you as soon as an error occurs:</p>
@@ -181,7 +181,33 @@ <h2><span class="glyphicon glyphicon-pushpin"></span>Post-mortem debugging with
<spanclass="co">'''Store airport codes in an array in numerical form'''</span>
195
+
to_numerical_code = numpy.vectorize(<spanclass="kw">lambda</span> code: numpy.array([<spanclass="dt">ord</span>(c) <spanclass="kw">for</span> c in code]))
196
+
<spanclass="kw">return</span> numpy.vstack([to_numerical_code(c) <spanclass="kw">for</span> c in codes])
0 commit comments