Feeds
Hotspot v1.4.0
Hotspot 1.4.0 has been released!
Hotspot is a replacement for perf report. It’s a GUI for the perf profiler that takes a perf.data file, parses and evaluates its contents, and then displays the result in a graphical way.
This feature release contains close to 400 commits since the last stable v1.3.0 release. It comes with its usual assorted list of bug fixes and performance improvements along with new features.
One of the most notable new features in Hotspot 1.4.0 is a greatly improved disassembly view with a godbolt-like source code annotation:
Several other new features come with this release of Hotspot as well, including:
- the self cost columns for tracepoints are now hidden by default, as they would always show 0 except for the function that contains the tracepoint. the inclusive cost column is much more useful
- more flexible window layouting with KDDockWidgets
- you can export and import data from hotspot in a custom format that is efficient to load and self-contained, meaning exported data can be read on any other machine with hotspot and does not require access to the original client application code for unwinding anymore note: this feature is broken in this release when using the AppImage, see #441 and stay tuned for a 1.4.1 release that will contain a fix for this issue
- analysis data can be grouped by thread, process or CPU
- demangling for the D programming language
- a new frequency page that shows how often certain events got measured, which can also indicate the CPU frequency scaling when cycles are measured
- new GitHub actions based CI and continuous AppImage build
Get Hotspot 1.4.0 here.
Read more about Hotspot and its background here.
The post Hotspot v1.4.0 appeared first on KDAB.
Django Weblog: DjangoCon US and Europe 2022 Talks Available Online
The organizers of DjangoCon US and DjangoCon Europe spend a tremendous amount of energy both hosting the conferences and putting all the talks online after. The complete playlists of talks from each conference are now available on YouTube:
PyCon: PyCon US 2023 Registration Launch!
The news you’ve been waiting for is finally here - registration for PyCon US 2023 is officially open!
PyCon US will take place April 19 - April 27, 2023, online and in Salt Lake City, Utah. The core of the conference, April 21 - April 23, 2023, packs in three days worth of our community’s 95 best talks, amazing keynote speakers, and our famed lightning talks to close out each day, but it is much more than that.
It’s gathering together with the members of our community, to learn from and share with. It’s joining a conversation in the hallway with the creators of open source projects. It’s taking yourself from beginner to intermediate, or intermediate to advanced. For some, it’s getting started with Python for the first time.
We hope you’ll join us for this special anniversary year, celebrating 20 years of PyCon.
Health & Safety GuidelinesPyCon US is committed to protecting the health and safety of our community. To ensure that we are gathering safely, we have implemented COVID-19 guidelines and protocols to be followed by all attendees during the event. We ask that you please review these guidelines prior to registration.
Please note: We will not be rolling back our mask requirement. If the situation changes and there are additional ways to keep attendees safe, we may incorporate those strategies closer to the event. Please check back regularly to stay updated on current guidelines.
How to RegisterOnce you have created an account on the PyCon US 2023 conference website, you can register via the registration button on your dashboard. Head over to our Registration Information page to get all the details on how to register.
Early Bird Registration RatesPyCon US is providing discounted rates for Corporate, Student, and Individual tickets for the first 500 tickets sold. Register now to get your discount while supplies last!
- Corporate - $650
- Individual - $350
- Student - $75
- Corporate - $750 USD
- Individual - $400 USD
- Student - $100 USD
- Online - $100 USD
- Patron / Patron Online - $1200 USD
Tutorials will be presented Wednesday, April 19, 2023, and Thursday, April 20, 2023. We are accepting proposals for tutorials through December 9, 2022. Find more information and submit a proposal here. Once our program committee has scheduled the selected tutorials, you will be able to add them to your conference registration.
Watch for tutorial launch in February 2023. Opt-in for PyCon US News and follow us on Twitter and Mastodon for the announcement.Sponsorship and Sponsor Presentations
Sponsorship for PyCon US 2023 is open now, and you can apply directly on our Sponsorship Application page. We’re grateful to all of our sponsors, who make PyCon US possible.
Sponsor Presentations will take place Thursday, April 20, 2023. To reserve a slot for an hour-long Sponsor Presentation on the topic of your choice, please apply for Partner Level Sponsorship or higher and select the check mark next to “Sponsor Presentation.” Slots are limited and typically sell out, so please submit your request soon. Contact sponsors@python.org with any questions.
HotelPyCon US has contracted special rates with nearby hotels. When you complete your registration for PyCon US 2023, you will be able to book a hotel reservation on your dashboard through our official housing bureau, Orchid Events. This is the only way to get the conference rates so book now while supplies last!
More information can be found on the Venue and Hotels page.
Note: Beware of Housing Pirates! PyCon US or Orchid Events will not be calling delegates to sell rooms. If you are contacted by an agency other than Orchid Events offering to make your hotel reservations, we urge you to not use their services. We cannot protect you against them if you do book a reservation.
Cancellation FeesRegistration cancellations must be submitted in writing and received by April 3, 2023, in order to receive a refund minus the $50 cancellation fee ($25 for students; waived for cancellation due to health reasons). No refunds will be granted for cancellations received after April 3, 2023, unless you must cancel for any health-related reasons (see more details under Attendance in the Health & Safety Guidelines).
In lieu of cancellation, you are able to transfer your registration to another person. For details about transferring your registration, visit the registration page.
Attendees traveling to PyCon US internationally are encouraged to review our International Travel Refund Policy as well as their countries' international travel guidelines prior to registering. This is especially important for recipients of Travel Grants attending from abroad. PyCon US strives to support the Python community in attending, no matter where they are traveling from.
Travel GrantsCheck out the Travel Grant page to learn more about the support we provide for travel, hotel, and registration to ensure that everyone has an opportunity to attend PyCon US. We actively encourage people to apply for travel grants and welcome applications from attendees who otherwise would not be able to attend. Our goal is to support diversity and provide equity to attendees and attract Python developers at all experience levels from around the world. For questions during the application process, visit the Travel Grant FAQ page.
Real Python: Python Basics: Dictionaries
In plain English, a dictionary is a book containing the definitions of words. Each entry in a dictionary has two parts: the word being defined, and its definition.
Python dictionaries, like lists and tuples, store a collection of objects. However, instead of storing objects in a sequence, dictionaries hold information in pairs of data called key-value pairs. That is, each object in a dictionary has two parts: a key and a value. Each key is assigned a single value, which defines the relationship between the two sets.
In this video course, you’ll learn:
- What a dictionary is and how it’s structured
- How dictionaries differ from other data structures
- How to define and use dictionaries in your own code
This video course is part of the Python Basics series, which accompanies Python Basics: A Practical Introduction to Python 3. You can also check out the other Python Basics courses.
Note that you’ll be using IDLE to interact with Python throughout this course.
[ 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 ]
The Fediverse unlocks a world of composable distributed apps
There’s more to Mastodon than just replacing Twitter. ActivityPub has the potential to end the reign of monetized surveillance with a switch to user-owned applications.
The post The Fediverse unlocks a world of composable distributed apps first appeared on Voices of Open Source.
PyPy: PyPy v7.3.10 release
The PyPy team is proud to release version 7.3.10 of PyPy. We have some nice speedups and bugfixes we wish to share. The release includes three different interpreters:
PyPy2.7, which is an interpreter supporting the syntax and the features of Python 2.7 including the stdlib for CPython 2.7.18+ (the + is for backported security updates)
PyPy3.8, which is an interpreter supporting the syntax and the features of Python 3.8, including the stdlib for CPython 3.8.15.
PyPy3.9, which is an interpreter supporting the syntax and the features of Python 3.9, including the stdlib for CPython 3.9.15. We have gained confidence in the stability of this version, and are removing the "beta" label.
The interpreters are based on much the same codebase, thus the multiple release. This is a micro release, all APIs are compatible with the other 7.3 releases. Highlights of the release, since the release of 7.3.9 in March 2022 include:
A release of Apple Silicon M1 arm64 versions. This work was sponsored by an anonymous donor and is tested on our buildbots.
Many improvements to the basic interpreter to make it 15-20% faster
The conda-forge community has built over 1000 packages for PyPy3.8 and 3.9, making it easier than ever to use PyPy.
Update the packaged OpenSSL to 1.1.1s, sqlite3 to 3.39.4, and apply applicable security fixes from CPython 3.9.15 to PyPy2.7
Update the HPy backend in PyPy3.8 and PyPy3.9 to 0.0.4
We recommend updating. You can find links to download the v7.3.10 releases here:
https://pypy.org/download.html
We would like to thank our donors for the continued support of the PyPy project. If PyPy is not quite good enough for your needs, we are available for direct consulting work. If PyPy is helping you out, we would love to hear about it and encourage submissions to our blog via a pull request to https://github.com/pypy/pypy.org
We would also like to thank our contributors and encourage new people to join the project. PyPy has many layers and we need help with all of them: bug fixes, PyPy and RPython documentation improvements, or general help with making RPython's JIT even better. Since the previous release, we have accepted contributions from five new contributors, thanks for pitching in, and welcome to the project!
If you are a python library maintainer and use C-extensions, please consider making a HPy / CFFI / cppyy version of your library that would be performant on PyPy. In any case, both cibuildwheel and the multibuild system support building wheels for PyPy.
What is PyPy?PyPy is a Python interpreter, a drop-in replacement for CPython 2.7, 3.8 and 3.9. It's fast (PyPy and CPython 3.7.4 performance comparison) due to its integrated tracing JIT compiler.
We also welcome developers of other dynamic languages to see what RPython can do for them.
We provide binary builds for:
x86 machines on most common operating systems (Linux 32/64 bits, Mac OS 64 bits, Windows 64 bits)
64-bit ARM machines running Linux (aarch64).
Apple M1 arm64 machines (macos_arm64).
s390x running Linux
PyPy support Windows 32-bit, Linux PPC64 big- and little-endian, and Linux ARM 32 bit, but does not release binaries. Please reach out to us if you wish to sponsor binary releases for those platforms. Downstream packagers provide binary builds for debian, Fedora, conda, OpenBSD, FreeBSD, Gentoo, and more.
What else is new?For more information about the 7.3.10 release, see the full changelog.
Please update, and continue to help us make pypy better.
Cheers, The PyPy Team
The Drop Times: A Look into Drupal Association Day One Meme Submissions
Annertech: Drupal 10: This is what we’re so excited about
In this blog we answer some of your Drupal 10 questions, and also tell you what new features we are looking forward to the most.
The Drop Times: ‘Everyday I’m Drupaling’ Music Video to Falling in Love with Drupal 10 Theming
Django Weblog: Django bugfix release: 4.1.4
Today we've issued the 4.1.4 bugfix release.
The release package and checksums are available from our downloads page, as well as from the Python Package Index. The PGP key ID used for this release is Carlton Gibson: E17DF5C82B4F9D00.
The Drop Times: 4 Videos to Get Accustomed to Drupal 10 Before Launch
Python Bytes: #313 Programming Robots With a Marker
Specbee: Starterkit Theme in Drupal 10: Implementing a Better Starting Point for your Theme
Frontend developers and themers have some exciting news coming up with the release of Drupal 10. The new starterkit theme is almost here! Although it has been available for testing since Drupal 9.5.
Starting with the basics, let's talk about themes. Themes are basically the foundation of the entire layout and design of your Drupal website. It is the layer of the website which is seen by end users and it comprises design components like color palettes, font, headers, footers, and other aesthetics of the site.
Now, sub-theming has been a core part of Drupal for a very long time. Sub-theming is the process of inheriting a parent theme’s resources. Creating a sub-theme in Drupal has generally been a manual process by typically inheriting from a core theme (Classy) or any contributed theme to use readily available markup and styling. Drupal Starter kit will completely change the perspective of sub-theming for developers. Read on to find out how and also learn to implement the new Starterkit theme.
Why use the Starterkit ThemeDrupal has been providing the ability to subtheme for a while now. But recently we all have noticed that the Classy theme has not been receiving any updates since Drupal 8.0.0 because it needs to maintain backward compatibility and any changes made might break it.
When you sub-theme a core theme, it uses the common markup and CSS of the parent theme. And if your Drupal site is dependent on a base theme like Classy, you will not have very few options to make any changes because Classy needs to retain backward compatibility. For that reason, the new concept of a Starterkit theme has been introduced in Drupal 10 core.
Features of the New StarterkitDrupal has introduced Starterkit in branch 10.0.x and the version is 10.0.0-beta1. It has replaced Classy which is now a contributed project.
- As the name suggests, Starterkit will act as a starting point to generate themes. It does not need to be extended as a base theme but rather copied onto the new theme.
- Drupal will provide frequent updates on the default markup and CSS in core so that these features will help Front-end developers.
- Sub-theming will still be an existing option to create subthemes. This is important in cases where themes are inheriting some common CSS and markup from the base Drupal theme.
- If a theme is already using the classy theme, it can continue doing so with the contributed classy theme, which will be the same as using the core Classy theme.
- You can generate a new theme using the command line interface tool.
Run this command in the respective (Drupal, docroot, web) folder to create a theme inside the theme folder.
php core/scripts/drupal generate-theme my_new_themeAdd your theme name in place of my_new_theme.
Example:
php core/scripts/drupal generate-theme testOn running this command, the theme is generated outside of the custom folder.
So to generate themes inside the custom folder, you will need to add the path of the file folder like so:
php core/scripts/drupal generate-theme test --path themes/customThe output will look like this:
To see all configuration options, you can reference the help:
php core/scripts/drupal generate-theme --help Customizing the StarterkitStarterkit tools provide the freedom to use a contributed or custom theme as the parent theme. For this, you need to add source_theme_name in the command line (which can you get from --help) and then add starterkit: true; in the theme in which you want as create a starter theme or sub-theme. (Remove starterkit: true; after generating the theme)
So finally, the command will look like this:
php core/scripts/drupal generate-theme my_new_them --path [path_of_file_folder] --starterkit source_theme_nameExample:
php core/scripts/drupal generate-theme demotheme --path theme/custom --starterkit bartikAnd the theme will look like this:
This theme is generated using Bartik theme and can be checked in the info.yml file of the theme
You can change the generated theme name, code, files, etc according to the requirements.
Tracking upstream changesWhen the theme is generated, you need to check for any upcoming changes in the Starterkit core, especially about features, bug fixes, etc. This is also important when you are using starterkit as your base theme
- Check the version of the core Starterkit theme
When you have generated a theme from Drupal core you need to check the version of the starterkit. You can check for it in the info.yml file in the generator key.
generator: starterkit_theme:9.3.0
With this you can now compare the version of the theme using Git or Drupal core repository.
Syntax
git diffExample:
git diff 9.3.0 9.4.0 core/themes/classy/- Check the list of theme changes by issue
If you find too many issues then you can review the changes from the list. Check the list of issues by using the below command:
Syntax
git logExample:
git log 9.4.0 9.3.0 core/themes/classy/ Final ThoughtsThere’s so much to look forward to in Drupal 10 with the Starterkit being a significant enhancement, especially for frontend developers. Enhancements and problem-solvers like the Starterkit proves that Drupal is a truly continuously evolving CMS and is on the right path to making it easier to adopt. As a purely Drupal development company, you can trust our experts to implement Drupal in the best way possible for your next project. We’d love to talk!
Author: Ashutosh Ahirwal
Meet Ashutosh Ahirwal, a Drupal Front-end Developer who is a big-time foodie and a travel enthusiast. Ashutosh is a night owl who fancies going on a long bike ride to Leh-Ladakh, admiring the nature around. He strongly believes there is no such thing as “too much cheese” :)
Drupal Development Drupal 10 Drupal PlanetLeave us a Comment
Recent Blogs Image Starterkit Theme in Drupal 10: Implementing a Better Starting Point for your Theme Image Things you need for a Drupal 8 to Drupal 9 Upgrade - A Checklist Image Getting Started with Layout Builder in Drupal 9 - A Complete Guide Want to extract the maximum out of Drupal? TALK TO US Featured Success StoriesUpgrading and consolidating multiple web properties to offer a coherent digital experience for Physicians Insurance
Upgrading the web presence of IEEE Information Theory Society, the most trusted voice for advanced technology
Great Southern Homes, one of the fastest growing home builders in the United States, sees greater results with Drupal 9
View all Case StudiesRead the Docs: Read the Docs newsletter - December 2022
This newsletter contains the first features and updates that have hatched since we announced a Q4 focus on core platform features in the previous newsletter.
News and updatesHere are the latest updates from our team:
⚙️ The entire build process can now be overridden (if you need it). See the Announcement.
💡️ This is useful if you want to publish outputs generated from a framework that isn’t supported by default. We wrote some examples for Pelican and Docsify.
💡️ You can also extend the build process for instance you can skip a build.
🐘️ We started tooting in the Fediverse (Mastodon). Follow us at @readthedocs@fosstodon.org
🛳️ Server-Side Search API v3 has been released.
🎬️ We are preparing to redirect our existing front pages to our new marketing site: about.readthedocs.com. Let us know know if you have comments or ideas for it.
⏳️ We organized a large refactor of our user documentation to comply with the Diátaxis methodology framework. So far, we broke it down into 73 tasks and counting.
✅️ We added a Policy for Unofficial and Unmaintained Projects that will help official maintainers to de-list forks among others.
✅️ We added an additional auditing feature, whereby invitations are added to the Security Log. The feature is available for users of Read the Docs for Business.
✅️ We found, fixed and disclosed a security issue, XSS: Allow serving of arbitrary HTML files from main domain.
You can always see the latest changes to our platforms in our Read the Docs Changelog.
Upcoming featuresWe’re working on improving our integration with Material for MkDocs, which is a great theme for MkDocs documentation projects.
Many improvements to our URL handling code, which will allow us to support more flexible URL configurations for projects.
A search redesign to make it nicer across our dashboard and in-doc search experiences.
404 pages are being improved by contextualization the user message, giving relevant guidance to readers and project owners.
Sphinx 6 is coming very soon. For those of you planning to upgrade immediately, we are preparing a blog post with a couple of considerations in that regard.
If you find regressions in any new releases of the sphinx-rtd-theme, please don’t hesitate to open an issue on GitHub.
Our Q4 focus also includes deprecating old and outdated approaches to using our platform. We don’t have anything firm to announce here yet, but we do plan to be more active in removing these features in the coming months.
Tip of the monthDo you need to document past or upcoming events? Chris Sewell has created sphinx-timeline for exactly this.
See sphinx-timeline in full action on the main page of AiiDA (which by the way is built with Read the Docs).
Awesome Project of the monthNautobot is a great example of a documentation landing page with several subprojects. See all the highlights in the following Twitter thread:
Nautobot is the project of our today’s 💫 Showcase the Docs 🌟 edition!
“An extensible and flexible Network Source of Truth and Network Automation Platform that is the cornerstone of any network automation architecture” #Nautobot #documentation pic.twitter.com/icp2q2Epty
Looking for more inspiration? Check out our new list: Awesome Read the Docs Projects.
Considering using Read the Docs for your next documentation project? Check out our documentation to get started!
Questions? Comments? Ideas for the next newsletter? Contact us!
GNUnet News: GNUnet 0.19.0
We are pleased to announce the release of GNUnet 0.19.0.
GNUnet is an alternative network stack for building secure, decentralized and
privacy-preserving distributed applications.
Our goal is to replace the old insecure Internet protocol stack.
Starting from an application for secure publication of files, it has grown to
include all kinds of basic protocol components and applications towards the
creation of a GNU internet.
This is a new major release.
It breaks protocol compatibility with the 0.18.x versions.
Please be aware that Git master is thus henceforth (and has been for a
while)
INCOMPATIBLE
with
the 0.18.x GNUnet network, and interactions between old and new peers
will result in issues. 0.18.x peers will be able to communicate with Git
master or 0.19.x peers, but some services will not be compatible.
In terms of usability, users should be aware that there are still
a number of known open issues
in particular with respect to ease
of use, but also some critical privacy issues especially for mobile users.
Also, the nascent network is tiny and thus unlikely to
provide good anonymity or extensive amounts of interesting information.
As a result, the 0.19.0 release is still
only suitable for early adopters
with some reasonable pain tolerance
.
- gnunet-0.19.0.tar.gz ( signature )
- gnunet-gtk-0.19.0.tar.gz ( signature )
- gnunet-fuse-0.19.0.tar.gz ( signature )
The GPG key used to sign is: 3D11063C10F98D14BD24D1470B0998EF86F59B6A
Note that due to mirror synchronization, not all links might be functional early after the release. For direct access try http://ftp.gnu.org/gnu/gnunet/
Noteworthy changes in 0.19.0 (since 0.18.2)- UTIL : Moved GNUNET_BIO_MetaData handling into FS .
- BUILD : platform.h removed as it should not be used by third parties anyway. gnunet_config.h is renamed to gnunet_private_config.h and the new replacement gnunet_config.h is added to provide build information for components linking against/using GNUnet.
- UTIL : Components part of gnunet_util_lib.h must now be included through gnunet_util_lib.h and through that header only .
- NAMESTORE : gnunet-namestore can now parse a list of records into zones from stdin in new recordline format.
- GTK : Added an identity selector to the search to accomodate for previously deprecated "default" identities for subsystems.
- Other: Postgres plugins implementations modernized and previous regressions fixed.
A detailed list of changes can be found in the ChangeLog and the bug tracker .
Known Issues- There are known major design issues in the TRANSPORT, ATS and CORE subsystems which will need to be addressed in the future to achieve acceptable usability, performance and security.
- There are known moderate implementation limitations in CADET that negatively impact performance.
- There are known moderate design issues in FS that also impact usability and performance.
- There are minor implementation limitations in SET that create unnecessary attack surface for availability.
- The RPS subsystem remains experimental.
- Some high-level tests in the test-suite fail non-deterministically due to the low-level TRANSPORT issues.
In addition to this list, you may also want to consult our bug tracker at bugs.gnunet.org which lists about 190 more specific issues.
ThanksThis release was the work of many people. The following people contributed code and were thus easily identified: Christian Grothoff, Tristan Schwieren, madmurphy, t3sserakt, TheJackiMonster and Martin Schanzenbach.
Talking Drupal: Talking Drupal #376 - Burnout
Today we are talking about Burnout with Jono Bacon.
For show notes visit: www.talkingDrupal.com/376
Topics- What is burnout
- Why is it so important to you
- Have you suffered from burnout
- Do different professions have different rates of burnout
- Is it individual or teams / projects / community oriented
- Is it only mental or can it be physical
- What contributes to burnout as a contributor or maintainer
- What can prevent burnout
- How do you recover
- First episode was Talking Drupal #265
- Helping communities
- Signs to watch out for
- What is next
- Ryan holiday book Obstacle is the way
- Talking Drupal #374 - Neurodiversity
- Talking Drupal #265 - People Powered
- Project Browser module Beta2 release
- Project Browser Strategic Initiative
Jono Bacon - www.jonobacon.com @jonobacon
HostsNic Laflin - www.nLighteneddevelopment.com @nicxvan John Picozzi - www.epam.com @johnpicozzi Leslie Glynn - @leslieglynn
MOTW CorrespondentMartin Anderson-Clutz - @mandclu Token The Token module provides a centralized API for text substitution. Since Drupal 7 some Token support is built into core, but the module provides common and reusable token UI elements and missing core tokens.
SystemSeed.com: Upgrade to Drupal 9 before Drupal 7 goes end-of-life
If your websites still use Drupal 7, you should be planning to upgrade to Drupal 9 as the end of life for Drupal 7 is drawing near
Lilian Ochieng Mon, 12/05/2022 - 17:59Real Python: Python News: What's New From November 2022
The Python world never stops spinning! After the release of Python 3.11 in October, the Python release team is already launching the first alpha versions of Python 3.12. The excitement of trying shiny new things shouldn’t distract you from being cautious while coding, though. Recently, researchers found more malicious packages on PyPI, and lawyers raised concerns about license violations when using GitHub Copilot to generate code.
Let’s dive into the biggest Python news from the past month!
Join Now: Click here to join the Real Python Newsletter and you'll never miss another Python tutorial, course update, or post.
Python 3.12 Alpha ReleasedOne of the most newsworthy events from October was the release of Python 3.11. While many of us are exploring the cool new features of Python 3.11, others are already hard at work on the next release.
Right on track with the Python 3.12 release schedule, the Python release team unveiled Python 3.12 alpha 2 in the middle of November. The core team is still early in the development cycle, but so far, the list of new features seems exciting.
Here’s some of what’s coming in Python 3.12:
- Even more improved error messages
- Support for the Linux perf profiler
- Deprecation of old functions, classes, and modules
While Python 3.11 already improved error messages, the next feature release will offer even better suggestions for fixing errors. For example, check out what it does when you forget to import a module or order your import statements wrong:
>>>>>> sys.version_info Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'sys' is not defined. Did you forget to import 'sys'? >>> import pi from math File "<stdin>", line 1 import pi from math ^^^^^^^^^^^^^^^^^^^ SyntaxError: Did you mean to use 'from ... import ...' instead?Especially when you’re learning Python, constructive error messages can point you in the right direction to improve your code. But also, if you’re a seasoned Python developer, then the upcoming Python release will have something in stock for your code improvements:
Read the full article at https://realpython.com/python-news-november-2022/ »[ 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 ]
Python for Beginners: Create Index in a Pandas Series
Pandas series objects are used to store data when we need to access it using its position as well as labels. In this article, we will discuss different ways to create index in a pandas series.
Table of Contents- Create Index in a Pandas Series Using the Index Parameter
- Create Index in a Pandas Series Using the Index Attribute
- Create an Index in a Pandas Series Using the set_axis() Method
- Create Index Inplace in a Pandas Series
- Conclusion
When we create a pandas series, it has a default index starting from 0 to the length of the series-1. For instance, consider the following example.
import pandas as pd import numpy as np letters=["a","b","c","ab","abc","abcd","bc","d"] series=pd.Series(letters) print("The series is:") print(series)Output:
The series is: 0 a 1 b 2 c 3 ab 4 abc 5 abcd 6 bc 7 d dtype: objectIn the above example, we have created a series of 8 elements. You can observe that the indices of the elements in the series are numbered from 0 to 7. These are the default indices.
If you want to assign a custom index to the series, you can use the index parameter in the Series() constructor. The index parameter in the Series() constructor takes a list having an equal number of elements as the elements in the series and creates a custom index for the series as shown below.
import pandas as pd import numpy as np letters=["a","b","c","ab","abc","abcd","bc","d"] numbers=[3,23,11,14,16,2,45,65] series=pd.Series(letters,index=numbers) print("The series is:") print(series)Output:
The series is: 3 a 23 b 11 c 14 ab 16 abc 2 abcd 45 bc 65 d dtype: objectIn the above example, we have passed the python list [3, 23, 11, 14, 16, 2, 45, 65] to the index parameter of the Series() constructor. After the execution of the Series() constructor, the elements of this list are assigned as the indices of the elements in the series.
Create Index in a Pandas Series Using the Index AttributeYou can also create a new index for a series after creating the series. For instance, if you want to assign other values as indices in the series, you can use the index attribute of the series object. To create a new custom index, you can assign a list of values to the index attribute as shown below.
import pandas as pd import numpy as np letters=["a","b","c","ab","abc","abcd","bc","d"] numbers=[3,23,11,14,16,2,45,65] series=pd.Series(letters) series.index=numbers print("The series is:") print(series)Output:
The series is: 3 a 23 b 11 c 14 ab 16 abc 2 abcd 45 bc 65 d dtype: objectIn this example, we have assigned the list [3, 23, 11, 14, 16, 2, 45, 65] to the index attribute of the series after creating the series. Hence, the elements of this list are assigned as the indices of the elements in the series.
Here, the list passed to the index attribute must have a length equal to the number of elements in the series. Otherwise, the program will run into a ValueError exception. You can observe this in the following example.
import pandas as pd import numpy as np letters=["a","b","c","ab","abc","abcd","bc","d"] numbers=[3,23,11,14,16,2,45,65,117] series=pd.Series(letters) series.index=numbers print("The series is:") print(series)Output:
ValueError: Length mismatch: Expected axis has 8 elements, new values have 9 elementsIn the above example, you can observe that the list "letters" has only 8 elements. As a result, the series contains only 8 elements. On the other hand, the list "numbers" has 9 elements. Hence, when we assign the "numbers" list to the index attribute of the series, the program runs into a ValueError exception.
Suggested Reading: If you are into machine learning, you can read this MLFlow tutorial with code examples. You might also like this article on clustering mixed data types in Python.
Create an Index in a Pandas Series Using the set_axis() MethodInstead of using the index attribute, we can use the set_axis() method to create an index in a pandas series.
The set_axis() MethodThe set_axis() method has the following syntax.
Series.set_axis(labels, *, axis=0, inplace=_NoDefault.no_default, copy=_NoDefault.no_default)Here,
- The labels parameter takes a list-like object containing index values. You can also pass an Index object to the labels parameter. The number of elements in any object passed to the labels parameter should have the same number of elements as the series on which the set_axis() method is invoked.
- The axis parameter is used to decide if we want to create the index for rows or columns. As a Series has only one column, the axis parameter is unused.
- After creating a new index, the set_axis() method returns a new Series object. If you want to modify the original Series object, you can set the inplace parameter to True.
- The copy parameter is used to decide whether to make a copy of the underlying data instead of modifying the original series. By default, it is True.
To create an index using the set_axis() method, we will invoke this method on the original series object. We will pass a list containing the new index values to the set_axis() method as an input argument. After execution, the set_axis() method will return a new series having a modified index. You can observe this in the following example.
import pandas as pd import numpy as np letters=["a","b","c","ab","abc","abcd","bc","d"] numbers=[3,23,11,14,16,2,45,65] series=pd.Series(letters) series=series.set_axis(labels=numbers) print("The series is:") print(series)Output:
The series is: 3 a 23 b 11 c 14 ab 16 abc 2 abcd 45 bc 65 d dtype: objectIn this example, we have first created a series containing 8 elements. Then, we used the set_index() method to assign new indices to the elements in the series. You can observe that the set_index() method returns a new series. Hence, the original series isn’t modified. To modify the original series by assigning new indices instead of creating a new one, you can create an index in place in the series.
Create Index Inplace in a Pandas SeriesTo create an index inplace in a pandas series, you can assign the new index to the index attribute of the series object as shown in the following example.
import pandas as pd import numpy as np letters=["a","b","c","ab","abc","abcd","bc","d"] numbers=[3,23,11,14,16,2,45,65] series=pd.Series(letters) series.index=numbers print("The series is:") print(series)Output:
The series is: 3 a 23 b 11 c 14 ab 16 abc 2 abcd 45 bc 65 d dtype: objectYou can also use the set_axis() method to create an index inplace in a series. For this, you can pass the list containing the new index values to the set_axis() method and set the inplace parameter to True while invoking the set_axis() method on the original series object. After execution, you will get the modified series object as shown below.
import pandas as pd import numpy as np letters=["a","b","c","ab","abc","abcd","bc","d"] numbers=[3,23,11,14,16,2,45,65] series=pd.Series(letters) series.set_axis(labels=numbers,inplace=True) print("The series is:") print(series)Output:
The series is: 3 a 23 b 11 c 14 ab 16 abc 2 abcd 45 bc 65 d dtype: objectIn this example, we used the set_index() method to assign new indices to the elements in the series. You can observe that we have set the inplace parameter to True in the set_index() method. Hence, the new indices are assigned in the original series object itself.
While using the inplace parameter you will get a FutureWarning stating "FutureWarning: Series.set_axis 'inplace' keyword is deprecated and will be removed in a future version. Use obj = obj.set_axis(..., copy=False) instead". It means that the inplace parameter has been deprecated. Hence, if the same code is used in future versions of pandas, the program may run into an error. To avoid this, you can use the copy parameter.
By default, the copy parameter is set to True. Hence, the set_axis() method uses a copy of the original series and modifies it. If you want to modify the original series, you can set the copy parameter to False in the set_axis() method.
ConclusionIn this article, we discussed different ways to create the index in a pandas series in Python. To know more about the pandas module, 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.
The post Create Index in a Pandas Series appeared first on PythonForBeginners.com.
Mike Driscoll: PyDev of the Week: Miroslav Šedivý
This week we welcome Miroslav Šedivý as our PyDev of the Week! Miro has been a speaker at several different Python conferences. You can also catch up with Miro on his website or by checking out Miro's GitHub Profile.
Let's take some time to get to know Miro better!
Can you tell us a little about yourself (hobbies, education, etc):My name is Miroslav Šedivý, but most people call me Miro, which allows them to avoid typing some letters they do not have on their keyboard. I was born in Czechoslovakia (yes, I am over 30 now), studied computer sciences in France and Germany, and now I am living in Austria.
Computers and programming were the hobbies that became my occupation. Another hobby, which is difficult to combine professionally with the first one, is human languages. As a Central European fascinated by travel, I speak a bunch of languages and enjoy using them every day.
Apart from this, I love spending time with my family, hiking, biking, fixing OpenStreetMap, camping, and woodworking.
You can find me at https://mas.to/@eumiro and occasionally at some Python events.
Why did you start using Python?After I have developed a quite complex power forecasting system for wind turbines in Perl using PDL (Perl equivalent to NumPy), my colleagues started using Python for new projects. It was around 2008, in the age of Python 2.5 with some rumors of Python 3. I got myself a book called “Perl to Python Migration” and tried to wrap my head around the new concepts.
The worst thing I remember from my beginnings was the necessity to "import re" each time I wanted to work with regular expressions. In Perl it was second nature to do almost anything with regular expressions. Not it Python. And this is beautiful about different languages: the way of thinking in them. Just like in French one does not simply count to seventy, nor in Czech say “one beer” (“one” is actually a synonym for “beer”), in Python one, can use other tools to dissect strings.
What other programming languages do you know and which is your favorite?There were some BASIC and Pascal somewhere in the past century, but now my number one is Python, accompanied by Shell. I remember some Perl, Java, C, and PHP from more or less serious projects in the past, and I have played with Go and Rust.
The choice of language usually depends on the task. I also do not use English to speak about food and cuisine, or Polish to comment a Python code review. I am using Python only for stuff it fits well. Luckily, it fits most of the stuff I am working on.
What projects are you working on now?Apart from my work, I have some sleeping projects at https://github.com/eumiro, which are currently waiting for another burst of enthusiasm or external input. A day has only 24±1 hours, but I wish it had more.
Which Python libraries are your favorite (core or 3rd party)?From standard lib, I am always happy if I can reach into the itertools module and simplify my code. Migration to Python 3 brings pathlib, which is a complete game changer when working with file system. I am also happy to see some gaps closing between the different modules, so you do not have to import anything else to obtain Unix timestamp of a datetime object, for instance.
There are plenty of wonderful third-party libraries I have worked with. The most important and complex one is probably pandas.
How did you end up contributing to open source projects?At my first Python conference EuroPython 2015 in Bilbao, I met Francesc Alted from the PyTables team and as an active user of the library I had a long discussion with him at the end, we even did a sprint and with his help, I removed one obsolete exception-raiser from the codebase that was bugging me since some time.
Later I occasionally contributed to some projects I was using, but then around Christmas 2020 I had quite a lot of free time and I discovered outdated CI/CD configurations in dozens of Python projects, so I started systematically helping them to fix the pipelines and also to modernize their code. This is where one of my talks “There Are Python 2 Relics In Your Code!” were born. Python 2 hacks like `int(math.floor(x))` work in Python 3 but they do not make sense in modern code and should be refactored.
What are the top three things you've learned as a contributor?Make small steps. Even smaller. If you think you've done a great bunch of work and submit a huge PR, the maintainers will have a very difficult time reviewing it and any rebase in an active project will probably stop their interest in your contribution.
Maintainers are humans with jobs paying their bills. Respect their time and energy and do not expect they're here only for you.
Comment on the project. Show how you're using it in your own work to make the maintainers feel their endeavor matters.
Is there anything else you’d like to say?Please do not use backslashes to deliberately break lines. If there's some line length limit (whether it is 78, 80, 88, 100, or 120), it makes your code more readable. There's virtually always a possibility to reformat your code to respect this limit and avoid horizontal scrolling in editor. Every such formatting allows you to break the line at a suitable position. Breaking lines with backslashes tells the reader “you have to join these lines in your head into a very long one to understand it.”
Finally, I'd like to thank Mike for his engagement and the whole Python community for collaborating on such a marvelous set of products and the whole ecosystem around it. So happy to be a part of it!
Thanks for doing the interview, Miro!
The post PyDev of the Week: Miroslav Šedivý appeared first on Mouse Vs Python.