Saturday, October 31, 2020

Python Bytes: #205 This is going to be a little bit awkward

<p>Sponsored by us! Support our work through:</p> <ul> <li>Our <a href="https://training.talkpython.fm/"><strong>courses at Talk Python Training</strong></a></li> <li><a href="https://testandcode.com/"><strong>Test &amp; Code</strong></a> Podcast</li> <li><a href="https://www.patreon.com/pythonbytes"><strong>Patreon Supporters</strong></a></li> </ul> <p><strong>Michael #1:</strong> <a href="https://awkward-array.org"><strong>Awkward arrays</strong></a></p> <ul> <li>via Simon Thor</li> <li>Awkward Array is a library for <strong>nested, variable-sized data</strong>, including arbitrary-length lists, records, mixed types, and missing data, using <strong>NumPy-like idioms</strong>.</li> <li>This makes it better than numpy at handling data where e.g. the rows in a 2D array have different lengths. It can even be used together with numba to jit-compile the code to make it even faster.</li> <li>Arrays are <strong>dynamically typed</strong>, but operations on them are <strong>compiled and fast</strong>. Their behavior coincides with NumPy when array dimensions are regular and generalizes when they’re not.</li> <li>Recently rewritten in C++ for the 1.0 release and can even be used from C++ as well as Python.</li> <li>Careful on installation: <code>pip install awkward1</code> ← Notice the 1.</li> </ul> <p><strong>Brian #2:</strong> <a href="https://nedbatchelder.com/blog/202010/ordered_dict_surprises.html"><strong>Ordered dict surprises</strong></a></p> <ul> <li>Ned Batchelder</li> <li>“Since Python 3.6, regular dictionaries retain their insertion order: when you iterate over a dict, you get the items in the same order they were added to the dict. Before 3.6, dicts were unordered: the iteration order was seemingly random.”</li> <li>The surprises: <ul> <li>You can’t get the first item, like d[0], since that’s just the value matching key 0, if key 0 exists. (I’m not actually surprised by this.)</li> <li>equality and order (this I am surprised by) <ul> <li>Python 3.6+ dicts ignores order when testing for equality</li> <li><code>{"a": 1, "b": 2} == {"b": 2, "a": 1}</code></li> </ul></li> <li>OrderdDicts care about order when testing for equality <ul> <li><code>OrderedDict([("a", 1), ("b", 2)]) != OrderedDict([("b", 2), ("a", 1)])</code></li> </ul></li> </ul></li> </ul> <p><strong>Michael #3:</strong> <a href="https://github.com/krassowski/jupyterlab-lsp">jupyter lab autocomplete and more</a></p> <ul> <li>via Anders Källmar</li> <li>Examples show Python code, but most features also work in R, bash, typescript, and many other languages.</li> <li><strong>Hover:</strong> Hover over any piece of code; if an underline appears, you can press Ctrl to get a tooltip with function/class signature, module documentation or any other piece of information that the language server provides</li> <li><strong>Diagnostics:</strong> Critical errors have red underline, warnings are orange, etc. Hover over the underlined code to see a more detailed message</li> <li><strong>Jump to Definition:</strong> Use the context menu entries to jump to definitions</li> <li><strong>Highlight References:</strong> Place your cursor on a variable, function, etc and all the usages will be highlighted</li> <li><strong>Automatic Completion:</strong> Certain characters, for example '.' (dot) in Python, will automatically trigger completion</li> <li><strong>Automatic Signature Suggestions:</strong> Function signatures will automatically be displayed</li> <li><strong>Rename:</strong> Rename variables, functions and more, in both: notebooks and the file editor.</li> </ul> <p><strong>Brian #4:</strong> <a href="https://source-separation.github.io/tutorial/landing.html"><strong>Open Source Tools &amp; Data for Music Source Separation</strong></a></p> <ul> <li>An online “book” powered by Jupyter Book</li> <li>By Ethan Manilow, Prem Seetharaman, and Justin Salamon</li> <li>A tutorial intended to guide people “through modern, open-source tooling and datasets for running, evaluating, researching, and deploying source separation approaches. We will pay special attention to musical source separation, though we will note where certain approaches are applicable to a wider array of source types.”</li> <li>Uses Python and interactive demos with visualizations.</li> <li>Section “basics of source separation” that includes a primer on digitizing audio signals, a look time frequency representations, what phase is, and some evaluations and measurements.</li> <li>Includes <ul> <li>use of a library called nussl</li> <li>deep learning approaches</li> <li>datasets</li> <li>training deep networks</li> </ul></li> <li>Brian’s comments: <ul> <li>Very cool this is an open source book</li> <li>Even if you don’t care about source separation, the primer on waveform digitization is amazing.</li> <li>The interactive features are great.</li> </ul></li> </ul> <p><strong>Michael #5:</strong> <a href="https://realpython.com/python-pass-by-reference/"><strong>Pass by Reference in Python: Background and Best Practices</strong></a></p> <ul> <li>Does Python have pointers?</li> <li>Some languages handle function arguments as <strong>references</strong> to existing variables, which is known as <strong>pass by reference</strong>. Other languages handle them as <strong>independent values</strong>, an approach known as <strong>pass by value</strong>.</li> <li>Python uses pass by assignment, very similar to pass by ref.</li> <li>In languages that default to passing by value, you may find performance benefits from passing the variable by reference instead</li> <li>If you actually want to change the value, consider <ul> <li>Returning multiple values with tuple unpacking</li> <li>A mutable data type</li> <li>Returning optional “value” types</li> <li>For example, how would we recreate this in Python? public static bool TryParse (string s, out int result);</li> </ul></li> <li>Tuple unpacking</li> </ul> <pre><code> def tryparse(string, base=10): try: return True, int(string, base=base) except ValueError: return False, None </code></pre> <pre><code> success, result = tryparse("123") </code></pre> <ul> <li>Optional types:</li> </ul> <pre><code> def tryparse(string, base=10) -&gt; Optional[int]: try: return int(string, base=base) except ValueError: return None </code></pre> <pre><code> if (n := tryparse("123")) is not None: print(n) </code></pre> <ul> <li>Best Practice: Return and Reassign</li> </ul> <p><strong>Brian #6:</strong> <a href="https://onlywei.github.io/explain-git-with-d3/"><strong>Visualizing Git Concepts</strong></a></p> <ul> <li>by <a href="https://github.com/onlywei">onlywei</a> Wei Wang</li> <li><a href="https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository">Git Basics</a> is good, and important, but hard to get all these concepts to sink in well until you play with it.</li> <li><a href="https://onlywei.github.io/explain-git-with-d3/">Visualizing Git Concepts with D3</a> solidifies the concepts</li> <li>Practice using git commands without any code, just visualizing the changes to the repository (and sometimes the remote origin repository) while typing commands. <ul> <li>commit, branch, checkout, checkout -b</li> <li>reset, revert</li> <li>merge, rebase</li> <li>tag</li> <li>fetch, pull, push</li> </ul></li> <li>Incredibly powerful to be able to play around with these concepts without using any code or possibly mucking up your repo.</li> </ul> <p>Extras:</p> <p>Brian: </p> <ul> <li><a href="https://microbit.org/new-microbit/">micro:bit now has a speaker and a microphone</a> - available in November</li> </ul> <p>Michael:</p> <ul> <li><a href="https://twitter.com/mkennedy/status/1316837032916705280"><strong>Firefox containers</strong></a></li> <li><a href="https://twitter.com/ChristosMatskas/status/1318551481021272064"><strong>Twitch!</strong></a> </li> </ul> <p>Joke:</p> <p><strong>Q:</strong> Where do developers drink? <strong>A:</strong> The Foo bar</p> <p><strong>-</strong> Knock Knock! <strong>-</strong> An async function <strong>-</strong> Who's there?</p>

from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...