Thursday, July 1, 2021

Python Bytes: #240 This is GitHub, your pilot speaking...

<p><strong>Watch the live stream:</strong></p> <a href='https://www.youtube.com/watch?v=CQ1w2Xu6MT8' style='font-weight: bold;'>Watch on YouTube</a><br> <br> <p><strong>About the show</strong></p> <p>Sponsored by <strong>us:</strong></p> <ul> <li>Check out the <a href="https://training.talkpython.fm/courses/all"><strong>courses over at Talk Python</strong></a></li> <li>And <a href="https://pytestbook.com"><strong>Brian’s book too</strong></a>!</li> </ul> <p>Special guest: <a href="https://twitter.com/chris1610"><strong>Chris Moffit</strong></a></p> <p><strong>Brain #1:</strong> <a href="https://hynek.me/articles/python-subclassing-redux/"><strong>Subclassing in Python Redux</strong></a></p> <ul> <li>Hynek Schlawack</li> <li>Prefer composition over inheritance,</li> <li>But if you must subclass, there are 3 types <ul> <li>subclassing for code sharing</li> <li>bad. don’t do it.</li> <li>read the article and included linked articles if you aren’t convinced</li> <li>Interfaces / Abstract Data Types</li> <li>Can be useful, but Python has tools that make this work without subclassing</li> <li>Specialization</li> <li>Exception hierarchies</li> <li>There’s also an interesting discussion of structuring data classes with common elements</li> <li>This is the only type of subclassing that Hynek deems worthy</li> </ul></li> <li>This is a well written, useful, and long-ish article that I cannot summarize and do it justice. </li> <li>My summary: If you even consider sublcassing other than for exceptions, read this article first.</li> </ul> <p><strong>Michael #2: Extra, Extra, Extra*7, Hear all about it!</strong></p> <ul> <li>New course! <a href="https://training.talkpython.fm/courses/python-powered-chat-apps-with-twilio-sendgrid-and-flask"><strong>Python-powered chat apps with Twilio and SendGrid</strong></a></li> <li><a href="https://hacks.mozilla.org/2021/04/pyodide-spin-out-and-0-17-release/"><strong>Pyodide is now an independent project</strong></a></li> <li><a href="https://twitter.com/Spirix3/status/1408213749505441797"><strong>Wow textual</strong></a> from Nick Mouh</li> <li><a href="https://arstechnica.com/gadgets/2021/06/google-delays-floc-rollout-until-2023/"><strong>#NoFLOC for real</strong></a>!</li> <li>Need to protect your Python source? <a href="https://pypi.org/project/sourcedefender/"><strong>SourceDefender</strong></a> <em>*</em>*(commercial product, but neat)</li> <li>I was a guest on <strong>A Day in a Life of a WFH Pythonista</strong>. Full episode <a href="https://youtu.be/oNydUs4KnAo?t=536"><strong>starts here</strong></a>, and <a href="https://youtu.be/oNydUs4KnAo?t=1882"><strong>the studio/office tour here</strong></a>.</li> <li><a href="https://www.python.org/downloads/release/python-396/"><strong>Python 3.9.6 is out</strong></a></li> <li><a href="https://sixfeetup.com/company/news/pwc2021-videos-released"><strong>Python Web Conf 2021 videos</strong></a> are out, including <a href="https://www.youtube.com/watch?v=A-3_Iw6KNCw&amp;list=PLt4L3V8wVnF4iB8pGfkR7eozIJPwCM7vv&amp;index=20"><strong>mine on memory</strong></a>.</li> <li><code>pip install pythonbytes</code> via <a href="https://github.com/stoltzmaniac/pythonbytes"><strong>pythonbytes package</strong></a>.</li> </ul> <p><strong>Chris #3:</strong> <a href="https://github.com/akanz1/klib"><strong>klib</strong></a></p> <ul> <li>Perform automated cleaning and analyzing of data in a pandas DataFrame</li> <li>Missing value plot and correlation data plots are similar to other tools but the visualizations are nicely done and useful. </li> <li>The data cleaning functions are really nice. In some testing, the automated data type conversion can save a meaningful amount of data.</li> <li>For large data sets, you can drop columns with lots of null values or highly correlated values.</li> <li>The clean_column_names function also performs several cleanups on column names such as removing spaces, standardizing CamelCase, etc. </li> <li>You have control to use as much or as little of the automated process as possible.</li> </ul> <p><strong>Brian #4:</strong> <a href="https://docs.python.org/3/library/functools.html"><strong>Don’t forget about functools</strong></a></p> <ul> <li>“functools — Higher-order functions and operations on callable objects” <ul> <li>in English: cool decorators and other functions that act on functions</li> </ul></li> <li>A <a href="https://martinheinz.dev/blog/52">recent article by Martin Heinz</a> reminded me to review <a href="https://docs.python.org/3/library/functools.html">functools</a></li> <li>We’ve talked about <code>singledispatch</code> recently, and I’m sure we’ve talked about <code>lru_cache</code> before. These are in <code>functools</code>.</li> <li><code>functools</code> is an interesting library in that you kind of use it more and more as you increase your Python experience. As a new Python dev, I would have been rather lost looking at this, but as you work through different projects, come back to this and have a look, it’ll have stuff you probably could have used, and will use in the future.</li> <li>What’s in there? Here’s a few: <ul> <li><code>@singledispatch</code> &amp; <code>@singledispatchmethod</code> - function/method overloading </li> <li><code>@wraps</code> - A must for creating your own decorators that makes the decorated function act just like the original function (attributes, docstring, and all, with just the added behavior you are adding. </li> <li><code>@lru_cache</code> - memoization made easy </li> <li>LRU = least recently used. It’s what it throws away when it’s full</li> <li><code>@cache</code> - like <code>@lru_cache</code> but with no max size. New in 3.9</li> <li><code>@cached_property</code> - only run the read code once. New in 3.8</li> <li><code>del(obj.property)</code> to clear it. Yes this is weird, but also cool.</li> <li><code>@total_ordering</code> - Define <code>__eq__()</code> and one other ordering function and get the other ordering functions for “free”. <ul> <li>not free. cost is slower execution and confusing stack traces if things go wrong. but still, when prototyping something, or when comparisons are very rare, this is cool</li> </ul></li> <li><code>partial</code> / <code>partialmethod</code> - create a new function with some of the arguments of the old function already filled in. </li> <li>super cool for callbacks or defining convenience functions</li> </ul></li> </ul> <p><strong>Michael #5:</strong> <a href="https://copilot.github.com/"><strong>GitHub Copilot</strong></a></p> <ul> <li>Get suggestions for whole lines or entire functions right inside your editor.</li> <li>Available today as a Visual Studio Code extension.</li> <li>The technical preview does especially well for Python, JavaScript, TypeScript, Ruby, and Go, but it understands dozens of languages and can help you find your way around almost anything.</li> <li>You can cycle through alternative suggestions</li> <li>Powered by Codex, the new AI system created by OpenAI</li> <li>Based on gpt3.</li> </ul> <p><strong>Chris #6:</strong> <a href="https://facebookresearch.github.io/Kats/"><strong>Kats</strong></a></p> <ul> <li>New tool from facebook for Time Series analysis</li> <li>Can use Facebook’s Prophet as well as other algorithms such as Sarima and Holt-Winters for prediction. Here’s my <a href="https://pbpython.com/prophet-accuracy.html">old post</a> on prophet.</li> <li>Some controversy about how well prophet performs in real life. Very detailed article <a href="https://www.microprediction.com/blog/prophet">here</a>.</li> <li>Provides utilities for analyzing time series including outlier and seasonality detection</li> <li>Offers advanced ensemble methods and access to deep learning algorithms</li> </ul> <p><strong>Extras</strong></p> <p><strong>Chris</strong></p> <ul> <li><a href="https://unyt.readthedocs.io/en/stable/">Unyt</a> - library for working with units of measure. <a href="https://pint.readthedocs.io/en/stable/">Pint</a> is another similar one with a different API.</li> </ul> <p><strong>Jokes</strong> </p> <p><a href="https://twitter.com/Dean_La/status/1286411422264700928"><strong>Italian Aysnc</strong></a> (from Dean Langsam)</p> <p><strong>Q:</strong> Why aren't cryptocurrency engineers allowed to vote? <strong>A:</strong> Because they're miners!</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...