Feeds

Talking Drupal: Talking Drupal #380 - Happy New Year

Planet Drupal - Thu, 2022-12-22 14:12

Today we share interviews conducted at NEDCamp in November 2022. This is an audio only episode.

For show notes visit: www.talkingDrupal.com380

Topics / Guests
  1. John Picozzi
  2. Shane Thomas
  3. Donna Bungard
  4. Chris Wells
  5. Jacob Rockowitz
  6. Leslie Glynn
  7. Mike Anello
  8. Mike Miles
  9. Nic Laflin
Hosts

Stephen Cross @stephencross

MOTW

with Martin Anderson-Clutz - @mandclu

Bookable Calendar Module https://www.drupal.org/project/bookable_calendar A very easy to use Bookable Calendar module. Whether you’re giving lessons and want your students to be able to book a lesson or a business trying to stagger traffic into your building, this module aims to get you up and running as fast as possible.

Categories: FLOSS Project Planets

Peter Bengtsson: Pip-Outdated.py - a script to compare requirements.in with the output of pip list --outdated

Planet Python - Thu, 2022-12-22 08:14

Simply by posting this, there's a big chance you'll say "Hey! Didn't you know there's already a well-known script that does this? Better." Or you'll say "Hey! That'll save me hundreds of seconds per year!"

The problem

Suppose you have a requirements.in file that is used, by pip-compile to generate the requirements.txt that you actually install in your Dockerfile or whatever server deployment. The requirements.in is meant to be the human-readable file and the requirements.txt is for the computers. You manually edit the version numbers in the requirements.in and then run pip-compile --generate-hashes requirements.in to generate a new requirements.txt. But the "first-class" packages in the requirements.in aren't the only packages that get installed. For example:

▶ cat requirements.in | rg '==' | wc -l 54 ▶ cat requirements.txt | rg '==' | wc -l 102

In other words, in this particular example, there are 76 "second-class" packages that get installed. There might actually be more stuff installed that you didn't describe. That's why pip list | wc -l can be even higher. For example, you might have locally and manually done pip install ipython for a nicer interactive prompt.

The solution

The command pip list --outdated will list packages based on the requirements.txt not the requirements.in. To mitigate that, I wrote a quick Python CLI script that combines the output of pip list --outdated with the packages mentioned in requirements.in:

#!/usr/bin/env python import subprocess def main(*args): if not args: requirements_in = "requirements.in" else: requirements_in = args[0] required = {} with open(requirements_in) as f: for line in f: if "==" in line: package, version = line.strip().split("==") package = package.split("[")[0] required[package] = version res = subprocess.run(["pip", "list", "--outdated"], capture_output=True) if res.returncode: raise Exception(res.stderr) lines = res.stdout.decode("utf-8").splitlines() relevant = [line for line in lines if line.split()[0] in required] longest_package_name = max([len(x.split()[0]) for x in relevant]) if relevant else 0 for line in relevant: p, installed, possible, *_ = line.split() if p in required: print( p.ljust(longest_package_name + 2), "INSTALLED:", installed.ljust(9), "POSSIBLE:", possible, ) if __name__ == "__main__": import sys sys.exit(main(*sys.argv[1:])) Installation

To install this, you can just download the script and run it in any directory that contains a requirements.in file.

Or you can install it like this:

curl -L https://gist.github.com/peterbe/099ad364657b70a04b1d65aa29087df7/raw/23fb1963b35a2559a8b24058a0a014893c4e7199/Pip-Outdated.py > ~/bin/Pip-Outdated.py chmod +x ~/bin/Pip-Outdated.py Pip-Outdated.py
Categories: FLOSS Project Planets

Ned Batchelder: Secure maintainer workflow, continued

Planet Python - Thu, 2022-12-22 07:03

Picking up from Secure maintainer workflow, especially the comments there (thanks!), here are some more things I’m doing to keep my maintainer workflow safe.

1Password ssh: I’m using 1Password as my SSH agent. It works really well, and uses the Mac Touch ID for authorization. Now I have no private keys in my ~/.ssh directory. I’ve been very impressed with 1Password’s helpful and comprehensive approach to configuration and settings.

Improved environment variables: I’ve updated my opvars and unopvars shell functions that set environment variables from 1Password. Now I can name sets of credentials (defaulting to the current directory name), and apply multiple sets. Then unopvars knows all that have been set, and clears all of them.

Public/private GitHub hosts: There’s a problem with using a fingerprint-gated SSH agent: some common operations want an SSH key but aren’t actually security sensitive. When pulling from a public repo, you don’t want to be interrupted to touch the sensor. Reading public information doesn’t need authentication, and you don’t want to become desensitized to the importance of the sensor. Pulling changes from a git repo with a “git@” address always requires SSH, even if the repo is public. It shouldn’t require an alarming interruption.

Git lets you define “insteadOf” aliases so that you can pull using “https:” and push using “git@”. The syntax seems odd and backwards to me, partly because I can define pushInsteadOf, but there’s no pullInsteadOf:

[url "git@github.com:"]
    # Git remotes of "git@github.com" should really be pushed using ssh.
    pushInsteadOf = git@github.com:

[url "https://github.com/"]
    # Git remotes of "git@github.com" should be pulled over https.
    insteadOf = git@github.com:

This works great, except that private repos still need to be pulled using SSH. To deal with this, I have a baroque contraption arrangement using a fake URL scheme “github_private:” like this:

[url "git@github.com:"]
    pushInsteadOf = git@github.com:
    # Private repos need ssh in both directions.
    insteadOf = github_private:

[url "https://github.com/"]
    insteadOf = git@github.com:

Now if I set the remote URL to “github_private:nedbat/secret.git”, then activity will use “git@github.com:nedbat/secret.git” instead, for both pushing and pulling. (BTW: if you start fiddling with this, “git remote -v” will show you the URLs after these remappings, and “git config --get-regex ‘remote.*.url’” will show you the actual settings before remapping.)

But how to set the remote to “github_private:nedbat/secret.git”? I can set it manually for specific repos with “git remote”, but I also clone entire organizations and don’t want to have to know which repos are private. I automate the remote-setting with an aliased git command I can run in a repo directory that sets the remote correctly if the repo is private:

[alias]
    # If this is a private repo, change the remote from "git@github.com:" to
    # "github_private:".  You can remap "github_private:" to "git@" like this:
    #
    #   [url "git@github.com:"]
    #       insteadOf = github_private:
    #
    # This requires the gh command: https://cli.github.com/
    #
    fix-private-remotes = "!f() { \
        vis=$(gh api 'repos/{owner}/{repo}' --template '{{.visibility}}'); \
        if [[ $vis == private ]]; then \
            for rem in $(git remote); do \
                echo Updating remote $rem; \
                git config remote.$rem.url $(git config remote.$rem.url | \
                    sed -e 's/git@github.com:/github_private:/'); \
            done \
        fi; \
    }; f"

This uses GitHub’s gh command-line tool, which is quite powerful. I’m using it more and more.

This is getting kind of complex, and is still a work in progress, but it’s working. I’m always interested in ideas for improvements.

Categories: FLOSS Project Planets

Python Software Foundation: More Python Everywhere, All at Once: Looking Forward to 2023

Planet Python - Thu, 2022-12-22 06:08
The PSF works hard throughout the year to put on PyCon US, support smaller Python events around the world through our Grants program and of course to provide the critical infrastructure and expertise that keep CPython and PyPI running smoothly for the 8 million (and growing!) worldwide base of Python users. We want to invest more deeply in education and outreach in 2023, and donations from individuals (like you) can make sure we have the resources to start new projects and sustain them alongside our critical community functions.

Supporting Membership is a particularly great way to contribute to the PSF. By becoming a Supporting Member, you join a core group of PSF stakeholders, and since Supporting Members are eligible to vote in our Board and bylaws elections, you gain a voice in the future of the PSF. And we have just introduced a new sliding scale rate for Supporting Members, so you can join at the standard rate of an annual $99 contribution, or for as little as $25 annually if that works better for you. We are about three quarters of the way to our goal of 100 new supporting members by the end of 2022 – Can you sign up today and help push us over the edge?

Thank you for reading and for being a part of the one-of-a-kind community that makes Python and the PSF so special.

With warmest wishes to you and yours for a happy and healthy new year,
Deb
Categories: FLOSS Project Planets

PyCharm: The PyCharm 2022.3.1 Release Candidate is out!

Planet Python - Thu, 2022-12-22 03:55

This build contains important bug fixes for PyCharm 2022.3. Look through the list of improvements and update to the latest version for a better experience.

Download PyCharm 2022.3.1 RC

  • Packaging: PyCharm no longer uses excessive disk space caching PyPI. [PY-57156]
  • HTTP client: Setting a proxy no longer breaks package inspection. [PY-57612]
  • Python console: Code that is run with the Emulate terminal in output console option enabled now has the correct indentation level. [PY-57706]
  • Inspections: The Loose punctuation mark inspection now works correctly for reStructuredText fields in docstrings. [PY-53047]
  • Inspections: Fixed an SOE exception where processing generic types broke error highlighting in the editor. [PY-54336]
  • Debugger: We fixed several issues for the debugger. [PY-57296], [PY-57055]
  • Code insight: Code insight for IntEnum properties is now correct. [PY-55734]
  • Code insight: Code insight has been improved for dataclass arguments when wildcard import is used. [PY-36158]

For the full list of improvements, please refer to the release notes. Share your feedback in the comments under this post or in our issue tracker.

Categories: FLOSS Project Planets

Talk Python to Me: #395: Tools for README.md Creation and Maintenance

Planet Python - Thu, 2022-12-22 03:00
If you maintain projects on places like GitHub, you know that having a classy readme is important and that maintaining a change log can be helpful for you and consumers of the project. It can also be a pain. That's why I'm excited to welcome back Ned Batchelder to the show. He has a lot of tools to help here as well as some opinions we're looking forward to hearing. We cover his tools and a bunch of others he and I found along the way.<br/> <br/> <strong>Links from the show</strong><br/> <br/> <div><b>Ned on Mastodon</b>: <a href="https://hachyderm.io/@nedbat" target="_blank" rel="noopener">@nedbat@hachyderm.io</a><br/> <b>Ned's website</b>: <a href="https://nedbatchelder.com" target="_blank" rel="noopener">nedbatchelder.com</a><br/> <br/> <b>Readme as a Service</b>: <a href="https://readme.so" target="_blank" rel="noopener">readme.so</a><br/> <b>hatch-fancy-pypi-readme</b>: <a href="https://github.com/hynek/hatch-fancy-pypi-readme" target="_blank" rel="noopener">github.com</a><br/> <b>Shields.io badges</b>: <a href="https://shields.io" target="_blank" rel="noopener">shields.io</a><br/> <b>All Contributors</b>: <a href="https://allcontributors.org" target="_blank" rel="noopener">allcontributors.org</a><br/> <b>Keep a changelog</b>: <a href="https://keepachangelog.com" target="_blank" rel="noopener">keepachangelog.com</a><br/> <b>Scriv: Changelog management tool</b>: <a href="https://github.com/nedbat/scriv" target="_blank" rel="noopener">github.com</a><br/> <b>changelog_manager</b>: <a href="https://github.com/masukomi/changelog_manager" target="_blank" rel="noopener">github.com</a><br/> <b>executablebooks' github activity</b>: <a href="https://github.com/executablebooks/github-activity" target="_blank" rel="noopener">github.com</a><br/> <b>dinghy: A GitHub activity digest tool</b>: <a href="https://github.com/nedbat/dinghy" target="_blank" rel="noopener">github.com</a><br/> <b>cpython's blurb</b>: <a href="https://github.com/python/core-workflow/tree/master/blurb" target="_blank" rel="noopener">github.com</a><br/> <b>release drafter</b>: <a href="https://github.com/release-drafter/release-drafter" target="_blank" rel="noopener">github.com</a><br/> <b>Towncrier</b>: <a href="https://github.com/twisted/towncrier" target="_blank" rel="noopener">github.com</a><br/> <b>mktestdocs testing code samples in readmes</b>: <a href="https://github.com/koaning/mktestdocs" target="_blank" rel="noopener">github.com</a><br/> <b>shed</b>: <a href="https://github.com/Zac-HD/shed" target="_blank" rel="noopener">github.com</a><br/> <b>blacken-docs</b>: <a href="https://github.com/adamchainz/blacken-docs" target="_blank" rel="noopener">github.com</a><br/> <b>Cog</b>: <a href="https://github.com/nedbat/cog" target="_blank" rel="noopener">github.com</a><br/> <b>Awesome tools for readme</b>: <a href="https://github.com/HaiDang666/awesome-tool-for-readme-profile" target="_blank" rel="noopener">github.com</a><br/> <br/> <b>coverage.py</b>: <a href="ttps://coverage.readthedocs.io" target="_blank" rel="noopener">coverage.readthedocs.io</a><br/> <b>Tailwind CSS "Landing page"</b>: <a href="https://tailwindcss.com" target="_blank" rel="noopener">tailwindcss.com</a><br/> <b>Poetry "Landing page"</b>: <a href="https://python-poetry.org" target="_blank" rel="noopener">python-poetry.org</a><br/> <b>Textual</b>: <a href="https://www.textualize.io" target="_blank" rel="noopener">textualize.io</a><br/> <b>Rich</b>: <a href="https://github.com/Textualize/rich" target="_blank" rel="noopener">github.com</a><br/> <b>Join Mastodon Page</b>: <a href="https://joinmastodon.org" target="_blank" rel="noopener">joinmastodon.org</a><br/> <b>Watch this episode on YouTube</b>: <a href="https://www.youtube.com/watch?v=K7jeBfiNqR4" target="_blank" rel="noopener">youtube.com</a><br/> <b>Episode transcripts</b>: <a href="https://talkpython.fm/episodes/transcript/395/tools-for-readme.md-creation-and-maintenance" target="_blank" rel="noopener">talkpython.fm</a><br/> <br/> <b>--- Stay in touch with us ---</b><br/> <b>Subscribe to us on YouTube</b>: <a href="https://talkpython.fm/youtube" target="_blank" rel="noopener">youtube.com</a><br/> <b>Follow Talk Python on Mastodon</b>: <a href="https://fosstodon.org/web/@talkpython" target="_blank" rel="noopener"><i class="fa-brands fa-mastodon"></i>talkpython</a><br/> <b>Follow Michael on Mastodon</b>: <a href="https://fosstodon.org/web/@mkennedy" target="_blank" rel="noopener"><i class="fa-brands fa-mastodon"></i>mkennedy</a><br/></div><br/> <strong>Sponsors</strong><br/> <a href='https://talkpython.fm/max'>Local Maximum Podcast</a><br> <a href='https://talkpython.fm/sentry'>Sentry Error Monitoring, Code TALKPYTHON</a><br> <a href='https://talkpython.fm/assemblyai'>AssemblyAI</a><br> <a href='https://talkpython.fm/training'>Talk Python Training</a>
Categories: FLOSS Project Planets

Deploying to Linux with CMake

Planet KDE - Thu, 2022-12-22 02:52

A while ago, I blogged about our CMake deployment API that allows you to enhance the cmake --install step with instructions that deploy Qt libraries, plugins and assets. At the time of writing, Linux was not supported yet.  But not anymore: Qt 6.5 comes with deployment support for Linux!

Categories: FLOSS Project Planets

xjm: Why sponsor a core committer?

Planet Drupal - Wed, 2022-12-21 20:40
Why sponsor a core committer? xjm Wed, 12/21/2022 - 19:40

This post was collaboratively authored with other Drupal core committers including quietone, pameeela, catch, effulgentsia, larowlan, lauriii, and Dries.

Categories: FLOSS Project Planets

Testing for the next release

Planet KDE - Wed, 2022-12-21 18:00

Next release will come soon, but since there have been some big changes it would be nice to have them tested by more people.

The biggest changes are to the playlist which can now open m3u files, supports adding both local files and urls, can be sorted, cleared and saved.

The other big changes are to the recent files, which has been rewriten to fix a bunch of bugs, see below.

To test you can use the flatpak beta

flatpak remote-add flathub-beta https://flathub.org/beta-repo/flathub-beta.flatpakrepo flatpak install flathub-beta org.kde.haruna flatpak run --branch=beta org.kde.haruna

or build it yourself

git clone https://invent.kde.org/multimedia/haruna.git cd haruna # append `-D CMAKE_INSTALL_PREFIX:PATH=/your/custom/path` to install to a custom location cmake -B build -G Ninja cmake --build build cmake --install build Full list of changes:
  • Playlist:
    • added options to, open m3u files, add files and urls, sort, clear and save the playlist
    • added context menu for the playlist items
    • added setting to remember playlist state
    • removed rowHeight setting
    • fixed "Increase font size when fullscreen" setting not working
  • Recent files: fixed ordering, showing duplicates, clearing and adding when list is full
  • Added command line option to override the ytdl format selection setting (this option is overwritten if the GUI setting is changed)
  • Added option to set a default cover for music files
  • Added MPRIS thumbnail
  • Added setting for subtitles to be rendered in black borders
  • Fixed OSD showing without text

Issues should be reported here: https://bugs.kde.org/enter_bug.cgi?product=Haruna&component=generic, but make sure to fill in the template and provide as much info as possible.

Categories: FLOSS Project Planets

Everyday Superpowers: TIL Debug any python file in VS Code

Planet Python - Wed, 2022-12-21 16:37

One of my frustrations with VisualStudio Code was creating a `launch.json` file whenever I wanted to debug a one-off Python file.

Today, I learned that you could add a debugger configuration to your user settings. This allows you always to have a debugging configuration available.

How to do this

Create a debugging (or launch) configuration:

  1. Select the "Run and Debug" tab and click "create a launch.json file"

2. Choose "Python File"

3. VS Code will generate a configuration for you. This is the one I used, where I changed the `"justMyCode"` to `false`, so I can step in to any Python code.

{ "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": false }

4. Copy the config (including the curly braces)

5. Open your user configuration (`⌘`/`Ctrl` + `,`) and search for "launch".

6. Click "Edit in settings.json"

7. Add your configuration to the `"configurations"` list.

This is what mine looks like, for reference:

... "launch": { "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": false } ], "compounds": [] }
Read more...
Categories: FLOSS Project Planets

Everyday Superpowers: What is Your Burnout Telling You?

Planet Python - Wed, 2022-12-21 11:37

I am glad that mental health is being discussed more often in the programming world. In particular, I would like to thank Kenneth Reitz for his transparency over the last few years and contributing his recent essay on developer burnout.
Having just recently experienced a period of burnout, I would like to share some ideas that might help you skirt by it in your own life.
And, before I go on, let me say loud and clear, there is absolutely no shame in experiencing, or reaching out for help from, anxiety, fear, anger, burnout, depression, or any other mental condition.
If you think you might be struggling with something, please reach out for help! You might have to reach out several times to multiple sources, but remember you are too valuable to waste time with this funk.


Read more...
Categories: FLOSS Project Planets

Everyday Superpowers: A Sublime User in PyCharm Land

Planet Python - Wed, 2022-12-21 11:37
I have written few articles about how Sublime Text has been such a great environment to get my work done—and there's more to come, I have been extremely happy with Sublime for years. But listening to Michael Kennedy and some guests on his Talk Python to Me podcast gush about PyCharm's great features made me wonder what I was missing. I was lucky to receive a trial license for PyCharm almost a year ago, but I found it opaque and harsh compared to my beloved Sublime. With my license ending soon and a couple new python projects at work, I thought I would invest some effort to get used to PyCharm and see if I could get any benefit from it. Read my thoughts of the first few months of using PyCharm.
Read more...
Categories: FLOSS Project Planets

Everyday Superpowers: New python web app not working?

Planet Python - Wed, 2022-12-21 11:37
How many times have you had the thrill of releasing a new service or app to the world, only to have it crashing down when you test the URL and find a server error page instead of your work? I'm collecting a few tips I use when I'm trying to figure out why the new python service I have set up is not working.
Read more...
Categories: FLOSS Project Planets

Everyday Superpowers: Using Sublime Text for python

Planet Python - Wed, 2022-12-21 11:37
Five or so years ago, I was frustrated by my coding environment. I was working on .net web sites and felt like I was fighting Microsoft's Visual Studio to get my work done. I started jumping between Visual Studio, Notepad++, Eclipse, and other programs. With all my jumping around, I was not really happy with my experience in any of them.
I came across an article that encouraged me to invest in my coding tools; that is to pick one program and dive deep into it, find out what it's good for, and try to enjoy it to its maximum, before looking to other tools.
Given that inspiration, I turned to Sublime Text and the myriad of how-to articles and videos for it, and within a month it was my favorite editor. I could list dozens of reasons why you should give it a try, but Daniel Bader has done a great job.
I list several packages that I find crucial to helping my development experience.
Read more...
Categories: FLOSS Project Planets

Real Python: Generate Images With DALL·E 2 and the OpenAI API

Planet Python - Wed, 2022-12-21 09:00

Describe any image, then let a computer create it for you. What sounded futuristic only a few years ago has become reality with advances in neural networks and latent diffusion models (LDM). DALL·E by OpenAI has made a splash through the amazing generative art and realistic images that people create with it.

OpenAI now allows access to DALL·E through their API, which means that you can incorporate its functionality into your Python applications.

In this tutorial, you’ll:

  • Get started using the OpenAI Python library
  • Explore API calls related to image generation
  • Create images from text prompts
  • Create variations of your generated image
  • Convert Base64 JSON responses to PNG image files

You’ll need some experience with Python, JSON, and file operations to breeze through this tutorial. You can also study up on these topics while you go along, as you’ll find relevant links throughout the text.

If you haven’t played with the web user interface (UI) of DALL·E before, then try it out before coming back to learn how to use it programmatically with Python.

Source Code: Click here to download the free source code that you’ll use to generate stunning images with DALL·E 2 and the OpenAI API.

Complete the Setup Requirements

If you’ve seen what DALL·E can do and you’re eager to make its functionality part of your Python applications, then you’re in the right spot! In this first section, you’ll quickly walk through what you need to do to get started using DALL·E’s image creation capabilities in your own code.

Install the OpenAI Python Library

Confirm that you’re running Python version 3.7.1 or higher, create and activate a virtual environment, and install the OpenAI Python library:

PS> python --version Python 3.11.0 PS> python -m venv venv PS> .\venv\Scripts\activate (venv) PS> python -m pip install openai $ python --version Python 3.11.0 $ python -m venv venv $ source venv/bin/activate (venv) $ python -m pip install openai

The openai package gives you access to the full OpenAI API. In this tutorial, you’ll focus on the Image class, which you can use to interact with DALL·E to create and edit images from text prompts.

Get Your OpenAI API Key

You need an API key to make successful API calls. Sign up for the OpenAI API and create a new API key by clicking on the dropdown menu on your profile and selecting View API keys:

On this page, you can manage your API keys, which allow you to access the service that OpenAI offers through their API. You can create and delete secret keys.

Click on Create new secret key to create a new API key, and copy the value shown in the pop-up window:

Always keep this key secret! Copy the value of this key so you can later use it in your project. You’ll only see the key value once.

Save Your API Key as an Environment Variable

A quick way to save your API key and make it available to your Python scripts is to save it as an environment variable. Select your operating system to learn how:

(venv) PS> $ENV:OPENAI_API_KEY = "<your-key-value-here>" (venv) $ export OPENAI_API_KEY="<your-key-value-here>" Read the full article at https://realpython.com/generate-images-with-dalle-openai-api/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Python for Beginners: Check for Not Null Value in Pandas Python

Planet Python - Wed, 2022-12-21 09:00

In python, we sometimes need to filter not null and null values. In this article, we will discuss different ways to check for not null in pandas using examples.

We can check for not null in pandas using the notna() function and the notnull() function. Let us discuss each function one by one.

Table of Contents
  1. Check for Not Null in Pandas Using the notna() Method
  2. Check for Not NA in a Pandas Dataframe Using notna() Method
  3. Check for Not Null Values in a Column in Pandas Dataframe
  4. Check for Not NA in a Pandas Series Using notna() Method
  5. Check for Not Null in Pandas Using the notnull() Method
  6. Check for Not Null in a Pandas Dataframe Using the notnull() Method
  7. Conclusion
Check for Not Null in Pandas Using the notna() Method

As the name suggests, the notna() method works as a negation of the isna() method. The isna() method is used to check for nan values in pandas.  The notna() function has the following syntax.

pandas.notna(object)

Here, the object can be a single python object or a collection of objects such as a python list or tuple.

If we pass a single python object to the notna() method as an input argument, it returns False if the python object is None, pd.NA or np.NaN object. For python objects that are not null, the notna() function returns True. You can observe this in the following example.

import pandas as pd import numpy as np x=pd.NA print("The value is:",x) output=pd.notna(x) print("Is the value not Null:",output)

Output:

The value is: <NA> Is the value not Null: False

In the above example, we have passed the pandas.NA object to the notna() function. Hence, it returns False.

When we pass a list or numpy array of elements to the notna() function, the notna() function is executed with each element of the array. After execution, it returns a list or array containing True and False values. The True values of the output array correspond to all the values that are not NA, NaN, or None at the same position in the input list or array. The False values in the output array correspond to all the NA, NaN, or None values at the same position in the input list or array. You can observe this in the following example.

import pandas as pd import numpy as np x=[1,2,pd.NA,4,5,None, 6,7,np.nan] print("The values are:",x) output=pd.notna(x) print("Are the values not Null:",output)

Output:

The values are: [1, 2, <NA>, 4, 5, None, 6, 7, nan] Are the values not Null: [ True True False True True False True True False]

In this example, we have passed a list containing 9 elements to the notna() function. After execution, the notna() function returns a list of 9 boolean values. Each element in the output list is associated with the element at the same index in the input list given to the notna() function. At the indices where the input list does not contain Null values, the output list contains True. Similarly, at indices where the input list contains null values, the output list contains False.

Check for Not NA in a Pandas Dataframe Using notna() Method

Along with the notna() function, python also provides us with the notna() method to check for not null values in pandas dataframes and series objects.

The notna() method, when invoked on a pandas dataframe, returns another dataframe containing True and False values. True values of the output dataframe correspond to all the values that are not NA, NaN, or None at the same position in the input dataframe. The False values in the output dataframe correspond to all the NA, NaN, or None values at the same position in the input dataframe. You can observe this in the following example.

import pandas as pd import numpy as np df=pd.read_csv("grade.csv") print("The dataframe is:") print(df) output=df.notna() print("Are the values not Null:") print(output)

Output:

The dataframe is: Class Roll Name Marks Grade 0 1 11 Aditya 85.0 A 1 1 12 Chris NaN A 2 1 14 Sam 75.0 B 3 1 15 Harry NaN NaN 4 2 22 Tom 73.0 B 5 2 15 Golu 79.0 B 6 2 27 Harsh 55.0 C 7 2 23 Clara NaN B 8 3 34 Amy 88.0 A 9 3 15 Prashant NaN B 10 3 27 Aditya 55.0 C 11 3 23 Radheshyam NaN NaN Are the values not Null: Class Roll Name Marks Grade 0 True True True True True 1 True True True False True 2 True True True True True 3 True True True False False 4 True True True True True 5 True True True True True 6 True True True True True 7 True True True False True 8 True True True True True 9 True True True False True 10 True True True True True 11 True True True False False

In the above example, we have invoked the notna() method on a dataframe containing NaN values along with other values. The notna() method returns a dataframe containing boolean values. Here, False values of the output dataframe correspond to all the values that are NA, NaN, or None at the same position in the input dataframe. The True values in the output dataframe correspond to all the not null values at the same position in the input dataframe.

Check for Not Null Values in a Column in Pandas Dataframe

Instead of the entire dataframe, you can also check for not null values in a column of a pandas dataframe. For this, you just need to invoke the notna() method on the particular column as shown below.

import pandas as pd import numpy as np df=pd.read_csv("grade.csv") print("The dataframe column is:") print(df["Marks"]) output=df["Marks"].notna() print("Are the values not Null:") print(output)

Output:

The dataframe column is: 0 85.0 1 NaN 2 75.0 3 NaN 4 73.0 5 79.0 6 55.0 7 NaN 8 88.0 9 NaN 10 55.0 11 NaN Name: Marks, dtype: float64 Are the values not Null: 0 True 1 False 2 True 3 False 4 True 5 True 6 True 7 False 8 True 9 False 10 True 11 False Name: Marks, dtype: bool Check for Not NA in a Pandas Series Using notna() Method

Like a dataframe, we can also invoke the notna() method on a pandas Series object. In this case, the notna() method returns a Series containing True and False values. You can observe this in the following example.

import pandas as pd import numpy as np x=pd.Series([1,2,pd.NA,4,5,None, 6,7,np.nan]) print("The series is:") print(x) output=pd.notna(x) print("Are the values not Null:") print(output)

Output:

The series is: 0 1 1 2 2 <NA> 3 4 4 5 5 None 6 6 7 7 8 NaN dtype: object Are the values not Null: 0 True 1 True 2 False 3 True 4 True 5 False 6 True 7 True 8 False dtype: bool

In this example, we have invoked the notna() method on a pandas series. The notna() method returns a Series of boolean values after execution. Here, False values of the output series correspond to all the values that are NA, NaN, or None at the same position in the input series. The True values in the output series correspond to all the not null values at the same position in the input series.

Check for Not Null in Pandas Using the notnull() Method

The notnull() method is an alias of the notna() method. Hence, it works exactly the same as the notna() method.

When we pass a NaN value, pandas.NA value, pandas.NaT value, or None object to the notnull() function, it returns False. 

import pandas as pd import numpy as np x=pd.NA print("The value is:",x) output=pd.notnull(x) print("Is the value not Null:",output)

Output:

The value is: <NA> Is the value not Null: False

In the above example, we have passed pandas.NA value to the notnull() function. Hence, it returns False.

When we pass any other python object to the notnull() function, it returns True as shown below.

import pandas as pd import numpy as np x=1117 print("The value is:",x) output=pd.notnull(x) print("Is the value not Null:",output)

Output:

The value is: 1117 Is the value not Null: True

In this example, we passed the value 1117 to the notnull() function. Hence, it returns True showing that the value is not a null value.

When we pass a list or numpy array to the notnull() function, it returns a numpy array containing True and False values. You can observe this in the following example.

import pandas as pd import numpy as np x=[1,2,pd.NA,4,5,None, 6,7,np.nan] print("The values are:",x) output=pd.notnull(x) print("Are the values not Null:",output)

Output:

The values are: [1, 2, <NA>, 4, 5, None, 6, 7, nan] Are the values not Null: [ True True False True True False True True False]

In this example, we have passed a list to the notnull() function. After execution, the notnull() function returns a list of boolean values. Each element in the output list is associated with the element at the same index in the input list given to the notnull() function. At the indices where the input list contains Null values, the output list contains False. Similarly, at indices where the input list contains integers, the output list contains True.

Check for Not Null in a Pandas Dataframe Using the notnull() Method

You can also invoke the notnull() method on a pandas dataframe to check for nan values as shown below.

import pandas as pd import numpy as np df=pd.read_csv("grade.csv") print("The dataframe is:") print(df) output=df.notnull() print("Are the values not Null:") print(output)

Output:

The dataframe is: Class Roll Name Marks Grade 0 1 11 Aditya 85.0 A 1 1 12 Chris NaN A 2 1 14 Sam 75.0 B 3 1 15 Harry NaN NaN 4 2 22 Tom 73.0 B 5 2 15 Golu 79.0 B 6 2 27 Harsh 55.0 C 7 2 23 Clara NaN B 8 3 34 Amy 88.0 A 9 3 15 Prashant NaN B 10 3 27 Aditya 55.0 C 11 3 23 Radheshyam NaN NaN Are the values not Null: Class Roll Name Marks Grade 0 True True True True True 1 True True True False True 2 True True True True True 3 True True True False False 4 True True True True True 5 True True True True True 6 True True True True True 7 True True True False True 8 True True True True True 9 True True True False True 10 True True True True True 11 True True True False False

In the output, you can observe that the notnull() method behaves in exactly the same manner as the notna() method.

Instead of the entire dataframe, you can also use the notnull() method to check for not nan values in a column as shown in the following example.

import pandas as pd import numpy as np df=pd.read_csv("grade.csv") print("The dataframe column is:") print(df["Marks"]) output=df["Marks"].notnull() print("Are the values not Null:") print(output)

Output:

The dataframe column is: 0 85.0 1 NaN 2 75.0 3 NaN 4 73.0 5 79.0 6 55.0 7 NaN 8 88.0 9 NaN 10 55.0 11 NaN Name: Marks, dtype: float64 Are the values not Null: 0 True 1 False 2 True 3 False 4 True 5 True 6 True 7 False 8 True 9 False 10 True 11 False Name: Marks, dtype: bool

In a similar manner, you can invoke the notnull() method on a pandas series as shown below.

import pandas as pd import numpy as np x=pd.Series([1,2,pd.NA,4,5,None, 6,7,np.nan]) print("The series is:") print(x) output=pd.notnull(x) print("Are the values not Null:") print(output)

Output:

The series is: 0 1 1 2 2 <NA> 3 4 4 5 5 None 6 6 7 7 8 NaN dtype: object Are the values not Null: 0 True 1 True 2 False 3 True 4 True 5 False 6 True 7 True 8 False dtype: bool

In the above example, we have invoked the notnull() method on a series. The notnull() method returns a Series of boolean values after execution. Here, the True values of the output series correspond to all the values that are not NA, NaN, or None at the same position in the input series. The False values in the output series correspond to all the NA, NaN, or None values at the same position in the input series.

Conclusion

In this article, we have discussed different ways to check for not null values in pandas. To learn more about python programming, you can read this article on how to sort a pandas dataframe. You might also like this article on how to drop columns from a pandas dataframe.

I hope you enjoyed reading this article. Stay tuned for more informative articles.

Happy Learning!

The post Check for Not Null Value in Pandas Python appeared first on PythonForBeginners.com.

Categories: FLOSS Project Planets

2022 is almost over, welcome 2023!

Open Source Initiative - Wed, 2022-12-21 09:00

As I’m closing out my first full year as executive director of the Open Source Initiative, I’m amazed by what our small team has accomplished. I’m proud to end the year with a solid 20% growth in revenue from sponsors and an even more impressive increase of the total number of corporate sponsors, to a whopping 51 up from 36 last year! 

But it’s individual members like you who make a difference. The OSI is a charity organization, which means that we always serve the public interest, not corporate sponsors. 

We’re running an end-of-year campaign: you can donate, join as a supporting member or at a professional level if you can afford to donate more.

Your contributions help strengthen the voice of Open Source communities, bolstering representation by an organization independent of corporate influence and with an international perspective.  

We started the year with the objective of putting OSI back in the spotlight of conversations about Open Source and open standards. The investment paid off, with 17 interviews published in publications ranging from Marketplace, Venturebeat to ZDNet and more.

2023 will be a challenging year, with a lot of legislation in Europe and the U.S. hitting the negotiating tables. We’re already working with our Affiliates on the EU Cyber Resilience Act and the US Securing Open Source Software Act

More challenges are on the horizon, with legislation about artificial intelligence on both sides of the Atlantic. Open Source is under similar scrutiny in other parts of the world, too. We coordinate with our Affiliate organizations worldwide to monitor those efforts and support their action locally.

In 2023 we will need your help and support – as well as joining in to celebrate the OSI’s 25th anniversary

I hope you enjoy this time of the year, spending time with family and friends.

If you missed our series and have some downtime over the break, be sure to check out: 

Stefano Maffulli
Executive Director, OSI
Follow me on Mastodon

I’ll be taking a short break, but I’m looking forward to chatting with you during informal office hours on Fridays, starting up again on Fridays in 2023.

In this month’s newsletter: Engagement on policy & standards

Deb Bryant gave a talk on “Formalizing Mentorship for Community Health and Professional Growth” at the Linux Foundation Member Summit in the US in early November. The focus was on strengthening the open ecosystem by supporting contributor growth, reducing project burnout, and providing constructive opportunities for companies to contribute to upstream projects. As an invited speaker, she also attended Justin Colannino and Luis Villa’s popular talk, “Are ML Models the New Open Source Projects?” which discussed software licenses, data in training models, and policy discussions. Security in the software industry was also a hot topic among attendees.

A lot of legislative change is coming in Europe, and OSI has been engaging to advocate for Open Source developers. Simon Phipps represented OSI at the bi-annual General Assembly of ETSI, a wireless standards body. He also participated in a European Commission panel on promoting sustainability of Open Source and spoke at two European conferences about the challenges posed by software patents in formal standards. OSI will continue to engage in January over the Cyber Resilience Act and other topics.

You can follow Deb Bryant and Simon Phipps’ work on US and EU-related policy in brief by subscribing to the OSI public-policy mailing list.

The OSI on Mastodon

We’ve got a new official social media channel for the Open Source Initiative on Mastodon. We’ve been working to get a proper, authenticated home in the Fediverse for several months and hope you’ll join us there! Follow OSI on Mastodon. Read the full story of how OSI got on the Fediverse.

Open Source software started in academic circles and AI is not different

Check out our fourth panel discussion on AI, focusing on how academics are sharing datasets and models: What do they need to be able to replicate experiments and improve on their knowledge? What legal obstacles do they find? What social norms prevent collaboration? Full video and transcript on Voices of Open Source.

The Fediverse unlocks a world of composable distributed apps

There’s more to Mastodon than just replacing Twitter. Read all about it on Simon Phipps’ opinion piece.

Take a survey – Raise $$ for OSI

The team at Uffizzi is running a survey to inform an open report on how the software community is thinking about on-demand Preview Environments.

For each completed survey, they’ll donate $5 to the OSI. The survey is completely anonymous and participation is voluntary. Take the survey now!

OSI in the news

In case you missed it, the OSI was featured in this article:

  • An article on Marketplace, about Mastodon and federated social networks, with comments by OSI’s executive director on the challenges to moderation on the Fediverse.
And a huge shoutout to all of our new and renewing sponsors New Renewing

Are you interested in sponsoring or partnering with the OSI? Please see our Sponsorship Prospectus. Contact us to find out more about how your organization can promote open source development, communities and software

Where to meet OSI staff and directors

Conferences are back! Our 2023 travel plans start with:

The post 2022 is almost over, welcome 2023! first appeared on Voices of Open Source.

Categories: FLOSS Research

Will Kahn-Greene: Volunteer Responsibility Amnesty Day: December 2022

Planet Python - Wed, 2022-12-21 07:59

Today is Volunteer Responsibility Amnesty Day where I spend some time taking stock of things and maybe move some projects to the done pile.

In June, I ran a Volunteer Responsibility Amnesty Day [1] for Mozilla Data Org because the idea really struck a chord with me and we were about to embark on 2022h2 where one of the goals was to "land planes" and finish projects. I managed to pass off Dennis and end Puente. I also spent some time mulling over better models for maintaining a lot of libraries.

[1]

I gave the post an exceedingly long slug. I wish I had thought about future me typing that repeatedly and made it shorter like I did this time around.

This time around, I'm just organizing myself.

Here's the list of things I'm maintaining in some way that aren't the big services that I work on:

bleach
what is it:

Bleach is an allowed-list-based HTML sanitizing Python library.

role:

maintainer

keep doing:

no

next step:

more on this next year

everett
what is it:

Python configuration library.

role:

maintainer

keep doing:

yes

next step:

keep on keepin on

markus
what is it:

Python metrics library.

role:

maintainer

keep doing:

yes

next step:

keep on keepin on

fillmore
what is it:

Python library for scrubbing Sentry events.

role:

maintainer

keep doing:

yes

next step:

keep on keepin on

kent
what is it:

Fake Sentry server for local development.

role:

maintainer

keep doing:

yes

next step:

keep on keepin on, but would be happy to pass this off

sphinx-js
what is it:

Sphinx extension for documenting JavaScript and TypeScript.

role:

co-maintainer

keep doing:

yes

next step:

keep on keepin on

crashstats-tools
what is it:

Command line utilities for interacting with Crash Stats

role:

maintainer

keep doing:

yes

next step:

keep on keepin on

paul-mclendahand
what is it:

Utility for combining GitHub pull requests.

role:

maintainer

keep doing:

yes

next step:

keep on keepin on

rob-bugson
what is it:

Firefox addon for attaching GitHub pull requests to Bugzilla.

role:

maintainer

keep doing:

yes

next step:

keep on keepin on

fx-crash-sig
what is it:

Python library for symbolicating stacks and generating crash signatures.

role:

maintainer

keep doing:

maybe

next step:

keep on keepin on for now, but figure out a better long term plan

siggen
what is it:

Python library for generating crash signatures.

role:

maintainer

keep doing:

yes

next step:

keep on keepin on

mozilla-django-oidc
what is it:

Django OpenID Connect library.

role:

contributor (I maintain docker-test-mozilla-django-oidc

keep doing:

maybe

next step:

think about dropping this at some point

That's too many things. I need to pare the list down. There are a few I could probably sunset, but not any time soon.

I'm also thinking about a maintenance model where I'm squishing it all into a burst of activity for all the libraries around some predictable event like Python major releases.

I tried that out this fall and did a release of everything except Bleach (more on that next year) and rob-bugson which is a Firefox addon. I think I'll do that going forward. I need to document it somewhere so as to avoid the pestering of "Is this project active?" issues. I'll do that next year.

Categories: FLOSS Project Planets

Pages