Wednesday, June 2, 2021

Python Bytes: #236 Fuzzy wuzzy wazzy fuzzy was faster

<p>Sponsored by Sentry:</p> <ul> <li>Sign up at <a href="https://pythonbytes.fm/sentry"><strong>pythonbytes.fm/sentry</strong></a></li> <li>And please, when signing up, click <strong><em>Got a promo code? Redeem</em></strong> and enter <strong>PYTHONBYTES</strong></li> </ul> <p>Special guest: <a href="https://twitter.com/anastasiatymo"><strong>Anastasiia Tymoshchuk</strong></a></p> <p><strong>Brian #1:</strong> <strong>Using accessible colors,</strong> <a href="https://github.com/HDembinski/monolens"><strong>monolens</strong></a> <strong>&amp;</strong> <a href="https://github.com/1313e/CMasher"><strong>CMasher</strong></a></p> <ul> <li>Tweet by Matthew Feickert, <a href="https://twitter.com/HEPfeickert">@HEPfeickert</a> <ul> <li>“I need to give some serious praise to fellow Scikit-HEP dev Hans Dembinski on his excellent <a href="https://github.com/HDembinski/monolens">monolens</a> tool for interactive simulation of kinds of color blindness. It works really quite well and the fact that is a pipx install away is awesome!</li> </ul></li> <li><a href="https://github.com/HDembinski/monolens">monolens</a> lets you “view part of your screen in greyscale or simulated colorblindness” <ul> <li>So simple. Just pops up a box that you can drag around your monitor and view stuff in greyscale.</li> </ul></li> <li>Reply tweet by Niko, <a href="https://twitter.com/NikoSarcevic">@NikoSercevic</a> <ul> <li>“I mean to use cmasher so I know it’s cb friendly”</li> </ul></li> <li><a href="https://github.com/1313e/CMasher">CMasher</a> : “Scientific colormaps for making accessible, informative and <em>cmashing</em> plots” <ul> <li>Provides a collection of scientific colormaps and utility functions to be used by different Python packages and projects, mainly in combination with matplotlib.</li> <li>Lots of great colormaps that are color blindness friendly.</li> <li>Just specify the CB friendly colormaps with plots, super easy.</li> </ul></li> </ul> <pre><code> # Import CMasher to register colormaps import cmasher as cmr # Import packages for plotting import matplotlib.pyplot as plt import numpy as np # Access rainforest colormap through CMasher or MPL cmap = cmr.rainforest # CMasher cmap = plt.get_cmap('cmr.rainforest') # MPL # Generate some data to plot x = np.random.rand(100) y = np.random.rand(100) z = x**2+y**2 # Make scatter plot of data with colormap plt.scatter(x, y, c=z, cmap=cmap, s=300) plt.show() </code></pre> <p><strong>Michael #2:</strong> <a href="https://pypi.org/project/rapidfuzz/"><strong>rapidfuzz: Rapid fuzzy string matching in Python and C++</strong></a></p> <ul> <li>via <strong>Mikael Honkala</strong></li> <li>Rapid fuzzy string matching in Python and C++ using the Levenshtein Distance</li> <li>“you mention fuzzywuzzy for fuzzy text matching in the last episode, and wanted to mention the rapidfuzz package as a high-performance alternative.”</li> <li>“non-rigorous performance testing of several alternatives (including fuzzywuzzy), and rapidfuzz came out on top with a sizable margin.”</li> <li>Simple Ratio example:</li> </ul> <pre><code> &gt; fuzz.ratio("this is a test", "this is a test!") 96.55171966552734 </code></pre> <p><strong>Anastasiia #3:</strong> <a href="https://www.structlog.org/en/stable/"><strong>Structlog to improve your logs</strong></a></p> <ul> <li>One of the best ways to improve logs is to add more structure to them</li> <li>Why do we even need to care about logs? <ul> <li>logs can provide visibility to production, what is actually happening</li> <li>logs can help to improve tracing of a bug, especially if logs are machine-readable and easy parseable</li> <li>logs can give you a clue why a bug or an exception occurred</li> </ul></li> <li>It’s super easy to start with Structlog, also easy to integrate it with ELK stack for further processing</li> <li>Features that you will get if switch your logs to use structlog: <ul> <li>readable structure of logs in key-value pairs</li> <li>easy to parse with any post processor to visualise logs and to have more visibility for your code</li> <li>you can create custom log levels and separate specific logs with event keys for each log</li> </ul></li> <li>I am working with structured logs for a couple of years and recommend everyone to try</li> </ul> <p><strong>Brian #4:</strong> <strong>xfail now works with pytest-subtests</strong></p> <ul> <li>Admittedly, there may be few people that care about this, but I’m one of them.</li> <li><a href="https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests">subtests are a kinda weird feature of unittest that came in with Python 3.4</a></li> <li>They’re really a context manager that you can use within a test function </li> <li>pytest started supporting them through a plugin, <a href="https://github.com/pytest-dev/pytest-subtests">pytest-subtests</a>, sometime in 2019</li> <li>With the plugin, you can use either the unittest style, or a fixture fixture style, without unittest.</li> <li>It’s a similar problem/solution that <a href="https://pypi.org/project/pytest-check/">pytest-check</a> solves to allow multiple failures per test case.</li> <li>But, like I said, they have some quirks. <ul> <li>See Paul Ganssle’s <a href="https://blog.ganssle.io/articles/2020/04/subtests-in-python.html">Subtests in Python</a> </li> <li><a href="https://testandcode.com/111">T&amp;C 111: Subtests in Python with unittest and pytest</a></li> </ul></li> <li>One quirk is that xfail didn’t work right. It’s discussed in both links above.</li> <li>Anyway, it’s fixed now, <a href="https://github.com/pytest-dev/pytest-subtests/pull/40">thanks to maybe-sybr</a>, as of version 0.5.0</li> <li>So you can now trust that xfail will work properly with subtest</li> </ul> <p><strong>Michael #5:</strong> <a href="https://pydantic-docs.helpmanual.io/usage/settings/"><strong>BaseSettings in Pydantic</strong></a></p> <ul> <li>via Denis Roy</li> <li>Create a model that inherits from <code>BaseSettings</code></li> <li>The model initialiser will attempt to determine the values of any fields not passed as keyword arguments by reading from the environment.</li> <li>This makes it easy to: <ul> <li>Create a clearly-defined, type-hinted application configuration class</li> <li>Automatically read modifications to the configuration from environment variables</li> <li>Manually override specific settings in the initialiser where desired (e.g. in unit tests)</li> </ul></li> <li>Get values from OS ENV or .env files</li> <li>Also has support for secrets files</li> </ul> <p><strong>Anastasiia #6:</strong> <strong>Take care of the documentation on your team will thank you later</strong></p> <ul> <li><a href="https://docs.readthedocs.io/en/stable/intro/getting-started-with-sphinx.html">Sphinx and ReadTheDocs</a> will make life of developers so much easier</li> <li>Everyone knows importance of documentation, but how to keep it up to date?</li> <li>In my experience, I tried to use Confluence, describe new features in detailed Jira tickets, write some hints in Google docs and sharing them with the team. It does not work, as documentation is getting outdated and piles up drastically</li> <li>Benefits of implementing continuous documentation for the code: <ul> <li>easy to support by writing docstrings, updating them when needed</li> <li>easy to find needed information in a centralised documentation</li> <li>easy to keep versioning for each new release of the code</li> <li><a href="http://readthedocs.org/">ReadTheDocs</a> if free for open source code</li> <li><a href="https://www.sphinx-doc.org/en/master/">Sphinx</a> will generate code reference documentation for the code</li> </ul></li> </ul> <p><strong>Extras</strong></p> <p><strong>Michael</strong></p> <ul> <li><code>pipx</code> is now part of the PyPA (<a href="https://twitter.com/HEPfeickert/status/1397940429690183680"><strong>via Matthew Feickert</strong></a>)</li> <li>I’ll be “speaking” at <a href="https://freecontent.manning.com/livemanning-conferences-developer-productivity/"><strong>Manning’s Developer Productivity conference</strong></a>. It’s free, so feel free to sign up.</li> <li><a href="https://twitter.com/alexwlchan/status/1399095011178958851"><strong>Cloud bills, they do pile up</strong></a>!</li> <li><a href="https://twitter.com/btskinn/status/1400078775543533574"><strong>Flake8-FastAPI</strong></a> (via Brian Skinn)</li> <li>Want to contribute to Jupyter? <a href="https://twitter.com/SShanabrook/status/1293621116968112128"><strong>Add a localization</strong></a>.</li> </ul> <p><strong>Brian</strong></p> <ul> <li>pytest uses. Please comment on <a href="https://twitter.com/brianokken/status/1399955798596341763?s=20">this thread</a> if you know of some great projects that use pytest, if they converted from something else, or just find it interesting that they use pytest.</li> </ul> <p><strong>Joke</strong> </p> <p>First time recursion</p> <p><img src="https://ift.tt/3wXdb8X" alt="" /></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...