Are you using Polars for your data science work?
There are many benefits to Polars directly, of course,
but you might not be aware of all the excellent tools and libraries that make Polars even better.
Examples include Patito, which combines Pydantic and Polars for data validation,
and Polars underscore encryption, which adds AES encryption to selected columns.
We have Christopher Trudeau back on Talk Python To Me to tell us all about his list of excellent libraries
to power up your Polars game, and even talk a bit about his new Polars course.
This is Talk Python To Me, episode 510, recorded May 22nd, 2025.
Check it out, folks.
we've got a new geeky theme song. I hope you enjoy this fun start to the episode.
If you want to download the entire mp3, grab it at talkpython.fm/flask song. Enjoy.
Welcome to Talk Python To Me, a weekly podcast on Python. This is your host, Michael Kennedy.
Follow me on Mastodon where I'm @mkennedy and follow the podcast using at talkpython,
both accounts over at fosstodon.org and keep up with the show and listen to over nine years of
at talkpython.fm. If you want to be part of our live episodes, you can find the live streams over
on YouTube. Subscribe to our YouTube channel over at talkpython.fm/youtube and get notified
about upcoming shows. This episode is brought to you by Sentry. Don't let those errors go unnoticed.
Use Sentry like we do here at Talk Python. Sign up at talkpython.fm/sentry. And it's brought
to you by Agency. Discover agentic AI with Agency. Their layer lets agents find, connect, and work
together any stack anywhere start building the internet of agents at talkpython.fm/agency
spelled a-g-n-t-c-y christopher welcome to talk python welcome back to talk python thank you
third time's the charm we'll see how it goes it's gonna go well i'm sure um we've got a really fun
topic lined up i think this is one of those kinds of shows where there's there's going to be something
for everybody. There might be a lot for some people and there's going to be like, oh, that's
the thing that made it worth listening because we're going to talk about a bunch of different
extensions, tools, techniques, et cetera, for working with Polars, one of the exciting data
frame libraries that we have these days. So super excited to have you here to tell us about that.
And I'm really interested to hear how it works with Django because that's what you talk about
and coming, right?
I honestly, I haven't done it.
There's no reason it shouldn't,
but I have yet to actually combine
the two pieces together.
Well, I have used Flask and Pandas together,
so surely Django and Polaris will go together.
I know actually that they would.
Shouldn't be a problem.
I think it's one of the beauties
of these kinds of libraries is at the heart,
although there are rust underneath
or other things underneath to get you the performance,
they're still just Python.
So, you know, you've got access to the code
and you can do what you want.
Yeah, I think there's probably some combinations
that people don't typically think of.
Like, for example, one of the things that I like to do
is I've got some dashboard-y thing,
either for Talk Python in the course, I can't remember,
but I want a bar graph.
And so I do some matplotlib thing
and have it generate a picture
and just return that as a picture dynamically at a URL,
you know, and just set the source.
to the image to be wherever that thing is generated from.
So there are really cool combinations,
though I suspect we will not be doing much of our typical web stuff this show, will we?
I'll drop mentions to my book because I have to.
That's the way it's supposed to work.
But otherwise, yeah, we'll stick to the data science world this time around.
Yeah, well, let's start there.
I know people probably have listened to you on the show
or on the RealPython podcast or in other places that you're doing all the things.
But, you know, tell us about yourself.
Feel free to mention your book so people know about them as well.
There you go.
Yeah, there's an old joke.
How do you know somebody runs a marathon?
Well, they'll effing tell you.
Well, authors are more or less in the same package.
It's a contractual obligation.
It is.
I wrote it about in my book, Chris.
There you go.
Exactly.
That's right.
And I guess while I've got you on air, you know, thank you for writing the foreword.
So yeah, I guess now I should sell myself as an author.
It's nowhere near as impressive as people think it's sound to be.
I guess I spend my spare time doing sort of Python education-y stuff with you and other
organizations, and writing is kind of part of that.
My day job is still helping organizations do technical stuff.
Sometimes that's architectural advice, and sometimes that's things like Agile and Lean
process driven things. My marketing people tell me to sell myself as a fractional CTO.
I have a hard time saying that with a straight face, but you know,
got to put it on the brochure. So there you go.
Well, if you don't want to take it so seriously, you could be an improper fraction.
There you go.
You could be like a two ace CTO.
I'm an irrational CTO. That actually makes sense.
I'm radical two over seven. Let's go. That's how much a CTO I am.
More seriously, though, I'm sure there are people listening who find that idea pretty interesting, fractional CTO or sort of fractional something beyond just like low level coder.
Tell people what that what is that like?
How do you get into that?
I got into it because I kind of fell into software management early on in my career.
There was a company I was at where I was it was a Windows based shop and I was hired as the Unix guy.
We all had this naive idea that we could port the product to Unix easily.
So I was their sole Unix architect person.
After about six months worth of work, we figured out this just wasn't going to happen.
And my VP got pregnant and went, want to be a manager?
And basically handed me the keys.
So I kind of learned by being thrown in the deep end as to how to do the technical management type stuff.
So my career has always kind of been a bit of a balance between that.
I like smaller organizations and I like helping them grow. So what that tends to mean is when it's really early on, when you're number two or three, you're coding like a line developer. And as the organization grows, you spend less time doing that. And because I've spent a lot of time in startups, I've done that journey many times.
So the fractional CTO idea essentially is to try to help smaller organizations that wouldn't necessarily be able to afford a full-time CTO with that kind of thing and sort of provide the kind of advice from things I've learned throughout that process over the years and then sort of help out as you go along.
And sometimes that's come in with a very specific target of help us architect something.
And sometimes that's more of a, we need some, it's sometimes referred to as adult supervision,
where somebody comes in and just sort of offers sort of the process advice, right?
Right.
Who's going to be this adult in the room that says, no, we're not rewriting that in a new JavaScript framework.
It was a third time this year.
Yeah. And often it's very hard in a startup to concentrate on things like CICD and testing and all the rest of it because you're trying to get to market. So it's all about those features. Well, if you don't balance that, it's going to bite you later on. Right. So I try to help with sort of that overall bigger picture as part of the organizations and get them going.
Cool. Yeah, I find even outside of that kind of stuff, sometimes it's hard to focus on the boring but important features that matter rather than like, hey, wouldn't it be cool if we refactored this or made that faster? Like, it doesn't need to be faster yet until you have more customers. What you need is this other thing, this PDF export that nobody wants to write.
Yeah. And as developers, you know, like the entertaining part of our job is learning the new thing. And oftentimes that's learning the new library. And sometimes that's great. And sometimes that's wasting a whole bunch of time because the old library would have been just as good and keep sort of plowing along. Right.
There's a phrase that I stole in my book.
See, I keep bringing it back to the book.
People talk about Django being old and it's like the difference between, you know, it's a dinosaur.
No, no, it's a shark.
They're still around.
They're still valuable.
They're just as old as the dinosaurs, but they're still part of the ecosystem.
Interesting.
Hopefully, you know, the gray hair at the temples here helps me provide a little more insight into that than, say, somebody fresh out of school.
Mm-hmm.
Yeah, you see those gray hairs?
That's C++.
Exactly.
Yeah, indeed.
Okay.
Well, let's talk data science and let's talk pollers.
So I guess there's a lot of people who have heard of pollers and are experts.
I see out in the live audience already.
There are some folks whose things they've created for pollers we're going to talk about in this show, actually.
So some people need no introduction to pollers.
But there are many people listening to the show who are just getting into Python, using this as one of the footholds to kind of get a feel for the space.
And they might go like, what is pollers?
Sure.
You know?
And what's a data frame?
Like, tell us about this.
Yeah, I was about to say, before we get to the pollers, maybe we should just start with a data frame.
So a data frame is kind of an in-memory spreadsheet sort of thing.
It's a data structure that consists of rows and columns.
And you do the same kind of things that you might do in Excel, but in your code.
There are a whole bunch of advantages to doing it in your code over doing it in Excel.
And in fact, the course that we're going to talk about gets into some of that.
But there are a bunch of different libraries out there that help you do this.
The big one that has been around for probably the longest and is the most popular is Pandas.
Pandas has made some interesting design decisions.
And as a result, there are some other more recent additions to the space that are trying to address some of those things that Pandas has done.
And Polars has become one of the more popular ones.
I saw just as we kicked in here, there was a comment already about, I like the coding style of Polars better than Pandas.
And this to me, this is also why I actually prefer Polars.
The interface to it is a lot more like object-oriented code, and it feels more Pythonic to me.
And as a result, it tends to be one of the libraries that I now head towards if I need to muck with a bunch of data and do those kind of data framey things.
It is almost every benchmark out there has marked it as being significantly faster than Pandas.
So that's a nice little advantage.
And it also includes methods to convert your data into pandas and other data frames as well.
So if you do get stuck and there's something that isn't there and because it's a newer library,
you can always just go, oh, give me the pandas version of this, run my pandas commands,
and then bring it back into the polar space where you make it a little more comfortable.
So it's a nice...
Right, it's two pandas and a from pandas sort of thing, yeah.
Yeah, and so it's a nice flexible sort of approach and it's a quick bear.
And one of the things I find, I'm not trying to dump on Pandas.
It's going to sound like that occasionally, but I really do.
I like the library.
It's very, very powerful, very, very useful.
It uses a lot of black magic.
And I find as a developer, as somebody with a software engineering background, sometimes
code can be distracting where you look at it and go, how does that even compile?
What is that?
What are they doing?
And that pulls me away from the, I'm trying to do something.
And I find some of the stuff in Pandas kind of falls into that bucket.
Whereas you just do nice little chained function calls in pollers.
And so you're reading, you know, filter, select kinds of things.
And it feels a lot cleaner to me.
So it tends to be where I want to go.
And then the other big advantage of it, which some of the other data frame libraries have,
but Pandas, as far as I know, doesn't, is lazy evaluation.
And this is the idea of rather than executing each operation as you call it, you can chain a bunch of things together and then call them all at the same time.
This tends to give you large amounts of speed up.
So, for example, if you're reading in a CSV file and you want to do something only on certain rows in that CSV file, the filter can throw those rows that aren't important.
And then you would only run the operation on those rows that you were interested in.
Of course, that tends to be an awful lot faster than going through every single row at a time.
It also tends to use less memory for the same reason, because you don't have to keep as much in memory at any given time.
So lazy evaluation can be a really, really powerful tool, particularly if you're using with really, really large data frames.
So that to me is, you know, the coding style was a nice selling point.
But being able to see that performance difference with the lazy evaluation was really what hit it home for me.
Yeah, they're both super cool. You know, I talked to Richie Bink, who is a creator of Polars, about three years ago or so on the podcast. And it was very interesting to talk about some of the philosophies. So, for example, the lazy evaluation is great because you could theoretically change the order. Like if I'm going to do some complicated math computation on a thing, we'll talk about some of those.
And then I'm going to filter it down based on some unrelated criteria like state or whatever, gender, who knows, and then get the answer.
If I did that in pandas, it would do the math on every single thing and then filter it down and give you the answer.
And maybe take the US as an example, that might be one fiftieth of the data that you wouldn't have to multiply.
So with pollers, it can even optimize.
Well, if there's a filter, do the filter first and then the calculation.
Yeah.
So it's got kind of an optimizer built in there as well.
This technology is very similar to what happens in databases.
So if you're doing more complex SQL, behind the scenes, the database for you goes and tries to optimize that to try to figure out what the best way of doing this for you.
And Polars has that built in as well.
It's got it built in on your calls specifically.
So you can take advantage of that even if it isn't the lazy evaluation.
But it can really, really shine in the case of lazy evaluation.
So if you're doing a complex query all in one chunk,
like a group by with a bunch of different aggregates,
it does still do the same thing,
which again gives you one of the ways that it'll speed up.
But particularly with lazy evaluation
where you might chain together 15 or 20 calls,
it'll figure out for you what the best order on that is
and that can make a big difference.
You can also see what it wants to do
and what its execution plan is.
I don't understand the output.
it's deep relational algebra
but for those who are into this stuff
you can actually see exactly what it's doing
and it gives you a little peek behind the curtain
this portion of Talk Python I Me is brought to you by Sentry
over at Talk Python
Sentry has been incredibly valuable
for tracking down errors in our web apps
our mobile apps and other code that we run
I've told you the story how more than once
I've learned that a user was encountering a bug through Sentry and then fixed the bug and let them
know it was fixed before they contacted me. That's pretty incredible. Let me walk you through the few
simple steps that you need to add error monitoring and distributed tracing to your Python web app.
Let's imagine we have a Flask app with a React front end and we want to make sure there are no
errors during the checkout process for some e-commerce page. I don't know about you, but anytime
money and payments are involved, I always get a little nervous writing code. We start by simply
instrumenting the checkout flow. To do that, you enable distributed tracing and error modern train
in both your Flask backend and your React frontend. Next, we want to make sure that you have enough
context that the frontend and backend actions can be correlated into a single request. So we enrich
a sentry span with data context. In your React checkout.jsx, you'd wrap the submit handler in a
ban call. Then it's time to see the request live in a dashboard. We build a real-time Sentry dashboard.
You spin up one using span metrics to track key attributes like cart size, checkout duration,
and so on, giving you one pane for both performance and error data. That's it. When an error happens,
you open the error on Sentry, and you get end-to-end request data and error tracebacks to easily spot
what's going on. If your app and customers matter to you, you definitely want to set up Sentry like
we have here at Talk Python.
Visit talkpython.fm/sentry
and use the code talkpython,
all caps, just one word.
That's talkpython.fm/sentry,
code talkpython.
Thank you to Sentry for supporting the show.
With databases,
there's usually some way to ask for
what's called an explain.
Like you got some query,
instead of saying run the query,
parse it and do the optimizer
and then tell me what you would do.
And that can be really helpful
for saying like finding an index or something.
Yeah.
Is it actually using this index or is it not?
But then there's something like that in polars as well, yeah?
Yeah, and it calls it explain as well.
So when you've got the lazy object, you can call explain on it and it'll show it.
It also has a graphical equivalent, so it'll spit out a little image,
that sort of flow chart-y kind of thing that shows you what it is as well.
So if you prefer the pictures over the obscure Greek letter references,
then that can show you what's going on.
Yeah, very nice, very nice.
All right.
Well, we are going to not talk about the exact subject of your course that you wrote, but I think we should maybe give it a quick shout out.
So your course that you wrote at Talk Python is Polars for the Power Users, Transform Your Data Analysis Game.
What we're going to talk about is a bunch of different cool tools that extend and power up polars.
But if people are interested in learning polars more from scratch, they could take your course.
So I'll be sure to link to that in the show notes.
Maybe give people a super quick rundown on what's on the course, and then we'll talk about all the items.
Sure.
As you might guess from the title, it kind of teaches your pollers.
And you can see on the screen there, there's a bunch of different icons as well.
What we're trying to do is essentially take you to that next step.
So if you're doing data science-y stuff in Excel and you're trying to figure out how to move to the Python world with this,
then this is kind of a course to try and help you do that.
And it does it through the Polars library.
So there's a whole bunch of different examples as you go along.
A lot of the examples will start with, hey, here's a spreadsheet.
Here's a thing that you're doing in the spreadsheet.
Here is how you would do that with the Polars library and Python code instead.
And why you might do that instead of doing a spreadsheet.
Polars has this concept of expressions and filters.
And they're the ways of performing operations on your data and then looking at different columns or different rows.
So the course starts out there and then starts getting even deeper into real world examples.
The final lesson is actually a case study.
We took a bunch of the GDP data from the United Nations and showed you how to clean some of it, how to combine it.
whenever you've got data in the real world,
even if it's from the same source,
you're going to go,
oh, I want this information from this column
and that information from that column,
but they aren't related.
So now we have to cross-reference.
So it covers how to sort of do all of that kind of stuff.
So it's sort of this journey of
how do you take some of the more basic CSV
and Excel type stuff and change it into Python
all the way along the line
to how do we actually create a report
on data from the real world
using Polars as your library for doing it.
Excellent.
Yeah, it's also very funny.
A very funny course.
I enjoyed it.
Okay.
Polars is pretty awesome, wouldn't you say?
Yes, that's a nice, you know, there you go.
How's that for a segue?
Pretty awesome.
In fact, let's reverse that.
We're going to talk about awesome Polars.
So there are so many of these awesome lists out there.
And, you know, if you are interested in something
and you haven't looked yet for an awesome list for it,
go do that.
There's got to be an awesome Django.
I know there's got to be an awesome Flask.
There's an awesome Async.
There's an awesome Python.
And Ddata has gone and created awesome Polar.
So what we're going to do is we're going to go to this curated list
and pull out 10-ish number of things that we think would be really interesting.
On the order of 10, yes.
We didn't count.
One of these days we'll start prepared.
Well, my tabs scroll off the screen, so I can't even count them.
So there we go.
But no, something on that scale.
We're going to go through a bunch of different little things that are great.
And for me, I just, like I said at the opening of the show, I really like these because it's
like, oh, it's not a big deal, but it just made all of my work way easier and is really
easy to adopt.
A lot of these things are actually not huge commitments.
It's not like redo your data stack in some other data frame library because you'll get
some benefit.
Like, no, you just plug this thing into your puller's work you're already doing and it's
really good.
So with that, let's start out on visualization.
What do you think?
Sure.
Yeah, and this one's almost independent of Polars.
I guess there's sort of this whole category of things that are already in the data science space.
And what is specific to Polars is the good news, which is Polars works with all those tools that you're used to working with.
So if you're already playing with Matplotlib or Seaborn or any of those, Polars will integrate with it just like Pandas does and most of the others.
Polars does have sort of specific integrations with Altair and HVplot.
So there's built-in calls on the data frame that essentially say,
go plot this and they will use those tools.
But even if you don't want to use those,
getting at a column, slicing a column out,
and then handing that column down to Matplotlib works more or less just like Bandus does.
So this integration works quite nicely.
Likewise, with tools like Jupyter or Marimo,
again, this isn't really Polar specific,
but there's nothing in Polars that stops you from using these tools.
And so, you know, you're not, you know, if you're moving from pandas,
this isn't a stopper.
All the other things, you don't have to learn everything else from scratch.
Everything you bring with you will continue to work without any problem.
Yeah, so on the Polars docs, we've got examples for HVPlot, MapPlotlib,
Plot9, Seaborn, Plotly, all these things.
And yeah, they look great.
Have you played with Altair much?
You know, I've not played with Altair much. I think I've done mostly Plotly and Seaborn lately.
Okay. Yeah. I still, I have a love-hate relationship with Matt Plotlib. I'm usually too lazy to learn anything else and I grumble every time I use it because I can't remember how to set X underscore or set underscore X and it drives me crazy. But it gives you results and that's what's important.
For sure. So you mentioned it, Marimo. I recently covered, talked with Akshay from the Marimo team. I'm impressed. I am super impressed with the way that Marimo came out, the way it looks. It seems like a really nice, just a very nice modern Jupyter style. What do you think of it?
So I've yet to play with it. I've done a bunch of reading on it. The theory behind it is something
that is beautiful to me. I actually don't use Jupyter. And the big thing, this big stopping
thing for Jupyter for me is it doesn't feel like it scales. And that's because the cells are stored
as JSON. So it's a great tool like a REPL where if you're experimenting with something, it's
fantastic. But as soon as you're trying to start doing that on a team, it can be problematic because
now you're trying to merge those JSON pieces. It doesn't work very well. And Marimo has essentially
tried to solve this from the ground up. Instead of creating JSON to store everything, it's actually
creating Python output, which means the documents that you're creating in Marimo actually can be
managed just like any other code. And although I haven't played with it myself, the theory behind
that to me is very, very beautiful. And the next time I dive into this space, this is definitely
going to be the one I'm going to be playing with. Yeah, it looks great to me too. I think even just
from a visual, like the way the UI works, I really, really like it. The other thing in addition to the
Python backing instead of the JSON backing in, as in file storage, is the reactive bits. Like one
of the things that always scares me about notebooks is like it can go one, five, two, seven. Yeah.
And you don't even know what happened
into the like number six one, right?
But it affects the way the notebook runs.
Like it's kind of like go-to statements in it,
but you get to pick randomly.
And this has a way to say these cells depend in this order.
And so there's a automatic refresh and stuff.
Anyway, bit of a diversion,
but I think it's worth paying attention to.
Okay, where were we again?
Well, next thing we want to talk about is DataFramely.
Claritive, Polars native data frame validation library.
So the data science, the first 80% of your work is cleaning the data and getting it into the right shape.
And then the second 80% of your work is coding.
And then there's that last 80% of the work, which is output.
I think my math might be off there.
It feels like it's right, though.
It feels that the reality is true, though.
And what DataFramely helps you do is that first 80%.
So this is from a group of folks at a company called Quantco,
and they're a data science consulting firm.
And it works a bit like Pedantic or DjangoRM.
See there, I brought it back.
There's a book on that.
So you can create a data class-like object here,
which inherits from DataFramely's schema class.
And inside of that, you declare what your expected columns
in a data framework.
So for example, you could specify a weight,
something that is a weight,
like heavier light is a float value
and an American zip code is a string.
And in addition to that declaration syntax,
you can also write rule methods on the class
to give you more complex validation code,
like this plus this have to be,
these two values have to work together
or these two values have to be unique
or those kinds of validation pieces.
Now, once you've got one of these schema objects, you then call its validation method, passing in your data frame.
And if the results are clean, you get back your data frame.
And if they aren't, you get an exception that describes each validation, telling you what rule failed, what rows it failed upon.
And there's also a soft validation mechanism called filter, which returns a data frame with the rows that passed and a failure info object with the rows that went wrong.
So if you don't want to just sort of stop because it's too bad, you want to react to the parts that aren't, you can dig in and sort of go from there.
So this is a nice little piece and it can definitely help you.
It doesn't fix the dirty data, but helps you detect it, which of course is your sort of first step as you go along.
Yeah.
One of the real challenges you can run into is the data, it parses or something, right?
Yes.
And so then math works.
But at the same time, that's not necessarily giving the right answers.
And you've got to figure out, well, why is this not working?
Yeah.
In fact, in the course, one of the examples we use, which is what you've got up on the
screen here as well, is oftentimes people will put an American zip code, which for our
non-American friends is a five-digit number or could be a nine one, which that just makes
it messy.
But let's stick with the five digits for now.
Well, it could have a leading zero.
Well, if you've stored that in, say, Excel as a number, then that leading zero gets chopped.
And now all of a sudden you've got this four digit thing, which isn't a valid zip code.
And so as part of your data cleaning, you have to detect that or as part of loading the file.
And you might have to say, hey, wait a second.
This shouldn't be an integer.
Please load this as a string.
And so what these validation mechanisms allow for you is to help you sort of catch this.
And so, for example, if you were processing that failed info object and the only things that failed were zip codes, well, then you could have some code in there that went, okay, I'll just make sure that I fix the padding on this and maybe deal with it automatically as part of your data pipeline.
Yeah, you can do something like this to catch it potentially.
This portion of Talk Python To Me is brought to you by Agency.
The Agency, spelled A-G-N-T-C-Y, is an open source collective building the Internet of Agents.
We're all very familiar with AI and LLMs these days, but if you have not yet experienced the
massive leap that agentic AI brings, you're in for a treat. Agentic AI takes LLMs from the world's
smartest search engines to truly collaborative software. That's where agency comes in. Agency is
a collaboration layer where AI agents can discover, connect, and work across frameworks.
For developers, this means standardized agent discovery tools, seamless protocols for interagent communication, and modular components to compose and scale multi-agent workflows.
Agency allows AI agents to discover each other and work together regardless of how they're built, who built them, or where they run.
And they just announced several key updates, including interoperability with Anthropics Model Context Protocol, MCP,
a new observability data schema enriched with concepts specific to multi-agent systems,
as well as new extensions to the OpenAgentic Schema Framework, OASF.
So are you ready to build the Internet of agents?
Get started with agency and join Crew AI, LangChain, Llama Index, BrowserBase, Cisco, and dozens more.
Visit talkpython.fm/agency to get started today.
That's talkpython.fm/agency.
The link is in your podcast player's show notes and on the episode page.
Thank you to the agency for supporting Talk Python.me.
It's weird the shadow that Excel casts, especially onto the data science world.
I'm thinking of how, or even science in general, there was some gene as in...
I was just about to mention the same example.
I think it was like MAR223 or something like that.
But if you put that to Excel, it's like, oh, March the 2nd?
You're like, no, no, no, no, no.
Yeah, yeah, yeah.
And in fact, even Polars to a certain extent has some of those kinds of problems.
The routine that you use to read in a CSV,
because CSV files don't actually have data type information inside of them,
it essentially makes a guess.
And it uses, I think by default, it's like the first thousand rows of the file to make an educated guess as to what the data types are.
And what can happen is, let's say your data is consistent in the first thousand rows and then row 1001 has something else.
Well, then it's going to die because it'll say, well, this is an integer and now you're giving me a float.
And because it didn't detect that this was supposed to be a float in the first place.
Now, the difference between Polars and Excel is Excel will just keep chugging along and
you may not discover that you've caused yourself this problem, whereas Polars actually expects
those columns to be a data type.
So it'll scream.
And part of your data cleaning process would be to catch those kinds of things and fix
that.
Yeah.
I mean, spreadsheets are awesome.
They're really cool, but they get overused.
Like I was doing something where I had a bunch of dates in a column and I'd selected all
of them just to copy them.
But, you know, at the bottom it says, here's the sum of this or whatever.
It told me like the sum of these 20 dates was like March 12th of some.
I mean, nope, don't think it is.
But, you know, okay.
If you.
Well, the beauty of the spreadsheets is they're very, very flexible.
And the pain of a spreadsheet is they're very, very flexible.
And so, you know, it's, yeah, you could end up missing some toes depending on where you're pointing the gun.
So one of the challenges, for example, with your zip code example is maybe the first thousand rows are West Coast people.
So every number looks like a five digit proper number.
But after that, you get to East Coast people, which start with zeros because it goes old to new, I guess, is the way they came up with it.
And that could be a challenge, right?
Even just simple stuff like parsing that.
OK, what is up next?
So we go on the patio and have this conversation.
Yeah, so essentially, just as a quick aside, there are a couple different libraries that essentially do the same thing as what we just talked about.
Patio, Petito, I'm not sure how you're supposed to say this, which wasn't actually on the awesome pullers list, but it's one I've come across before.
This is by Jacob Gerard Martinson, and it's built on top of Pydantic.
Like with DataFramely, you declare a class inheriting from a model, then validate against it.
The twist on this one that I kind of liked is it also has a mechanism for generating data.
So if you're writing unit tests, once you've got this validator, you can go through and say, oh, give me some data to unit test with.
And it will give you data that complies with your model.
So I thought that was kind of an interesting little twist for helping you build your pipelines.
Yeah, it's super neat.
If you're a fan of Pydantic, this looks really, really cool.
You get basically the type of errors you would get parsing JSON with a Pydantic model.
It's the exact same error messages you get, but for data frame validation.
So I think that that's pretty cool.
Yeah, so it's nice and familiar.
Yeah, definitely.
If you're a FastAPI person or Pydantic for whatever reason.
Also, Patito, not patio, I suspect it probably is.
I want to start a trend.
I want to try to put something out there in the world for people.
If you've got something that could have multiple pronunciations, put just a little MP3 or something in your repo.
It sounds like this.
You know what?
I'm not sure that that's helpful because you remember the whole how do you pronounce Linux debate back in the 90s?
One of the, I think it was Slackware distribution I had, came with an MP3 of Torvalds pronouncing it.
And of course, with his accent, it didn't solve the problem.
So I'm not sure that MP3 is actually the answer.
Maybe just a little hyphenated where you want to put the stress of it.
So yeah, I think I saw a GIF or was it a GIF about it?
I don't know.
Yeah, exactly.
That's right.
Just something to help us figure it out.
That gives us a fight about on the internet.
Yeah, that's right.
Let's make memes about it.
Okay.
So the next one is Polars IP tools.
Pretty sure that's how we'd say this for you.
Yeah, this one's less debating.
Yeah.
So this is a library by Eric Hutchins.
And if you're playing with IP addresses, this could be helpful to you.
It essentially provides a bunch of data frame methods for mucking around with IP addresses in a column.
One of the functions it provides is private.
This returns true if the address is a private network.
So if, you know, 192, 168 or one of those groupings that's private, then you get true or false based back from it.
Another method is in.
So you give it a list of addresses with masks, and then it'll give you true or false for every IP address as to whether or not it's in that specific group of ranges.
The library also integrates MaxMind's GeoIP address database, if you've got access to that, as well as the Spur VPN database, which contains information about what's a proxy, what's a VPN, that kind of stuff.
So if you're doing a whole bunch of log management and you're dealing with all those IP addresses
that are coming in your logs and you want to use pullers to muck around with that and create
reports, then IP tools might be helpful for some of that kind of stuff.
Yeah.
If you're doing online sales, you want to know where the sale is coming from or where's
the interest coming from, say for marketing, this would be super valuable.
Once a sale happens, often you can say, well, they put their address or zip code or credit
card information we can see that but there's way more traffic upstream from that that doesn't
necessarily buy things right you can see where the interest is and and so on i actually don't use this
library but i use the max mine stuff over at talk python because when you come to visit a course i
want to show it in your currency well what is your currency well it belongs to your country
what is your country you probably haven't told me but i know your ip address so let me see if i can
figure that out and at least get it right most of the time so yeah this is cool right fuzzy match
So this is great.
Who's geese?
Which is it?
Which am I finding?
Exactly.
So from moving from IP addresses, which are very specific strings to some more generic ones,
the Polars Fuzzy Match Library does kind of what you would expect from its name.
The GitHub user's name was bnmock3.
He didn't write it as his full name.
So that's what we're going to go with.
His avatar or their avatar is delightful.
iSquare symbol non-ASCII characters, which is funny. So if you're not familiar with fuzzy matching,
it's about approximate matches on a string. So this library comes with a function that returns
a score based on the thing that you're matching. So let's say I had a series of strings that I
wanted to match against the word car, and that list had care and card in it. Those are close,
so they might have a score of like 80 something. Well, frog, which has nothing in no relationship
shift a car that scores a null. So this allows you to sort of see how close you are. And the fuzzy
matching routine that they're using is based on an underlying Rust library called Nucleo,
which comes out of the Helix editor. So it's supported in a whole bunch of different ways.
This isn't just some random guy on the internet. And it also has a bunch of strength, a bunch of
ways of specifying patterns like submatches starts with suffix matches, inverted matches,
and more. I kind of like the suffix match feature. So it allows you to do fuzzy matching just on,
say, the suffix part of the extension part of a file name and ignore the rest. So you can,
you know, whether they mucked up MP3 or MP4 or whatever. So that's kind of a neat little piece.
And then along the same lines, the next one's Polars STR-SIM.
It is, so fuzzy matching is based on something called a distance calculation.
And this essentially takes two strings and then gives you a value for,
typically it's between one and zero as to how close they match.
So if they're identical, it gives you a one.
And if they have nothing in column, it gives you a zero.
The most popular of these is Levenstein distances, but there are other ways out there.
The Jacquard, for example, or the Sorensen dice or whatever.
Yeah, I wasn't even going to attempt that.
So thank you.
These kinds of calculations get used in things like, say, spell checking software.
So if you've got something that isn't in the spelling dictionary and it wants to make a
suggestion, then what it does is it runs one of these kinds of distances on a bunch of
words in the dictionary and those values that are close are the suggestions that it'll give you.
So the Polars STR sim library, which is from a fellow Canadian, Jeremy Foxcroft,
allows you to calculate these string distances on your data frames. As you mentioned, it supports a
whole bunch of mechanisms, which I'm not even going to pretend to pronounce. And each of the
calculators basically takes two column names and then calculates the distances between them,
which makes it really easy to include in something like a with_columns call
so that you can just sort of add this to your data frame
and go along with your distance information.
So if you're trying to do partial matching,
either of these two libraries could be helpful for you.
Yeah, they seem really great.
Just a little bit of a side note here.
I think this is an interesting pattern with this Nucleo Rust library
that is actually kind of the foundation of the Polars Fuzzy Match, right?
I think this is something people should kind of keep their eye on out there.
like okay so this is not super popular but you might think well maybe it's not going to work that
well but if it's just kind of a wrapper around something that is super popular right an example
would be um granian i had giovanni on the show to talk about the granian python production worker
process thing and it's getting pretty popular 3.5k but you know you look at say uveacorn or something
like that but then really what it is kind of a wrapper around hypercrate well hypercrate is way
popular written in rust right used by 360 000 projects and 400 contributors like oh okay so
brand is kind of like an interface to hyper in a sense right and that's also a little bit what's
going on here and so when you're evaluating these libraries i think that's worth keeping in
mind what do you think yeah no for sure like it's um you know not that you can't not that you can't
create bugs in in a wrapper because you can create bugs in anything but uh you know the less code the
less likely there's a problem. And, you know, if it's built, if it, like you say,
if it's just a thin veneer on something that is big and popular and well-maintained, then,
you know, the fact that it's a thin veneer becomes less, less important.
Right. Right. Like, well, that veneer is not that popular. Like that veneer doesn't matter
that much. Okay. Maybe you should encrypt it though. If it had some sort of data,
you should encrypt it.
There you go. And this, this is another one actually that, you know, we'll pretend we
planned that. so this is another one, which is a thin veneer. so if you want to be sneaky
with your text here.
Niazi Garagashli,
which I'm sure I'm butchering,
has written Polars Encryption.
This library incorporates AES ciphers
into Polars,
providing encrypt and decrypt functions
as expressions.
So if you're mucking around
with, say, personally identifiable information,
or you're just like sending
other data scientists secret messages
about your pointy-haired boss,
then this little veneer
could actually be fairly useful to you.
Well, I'm thinking of maybe there's
encryption at rest type of stuff you want to be having going on.
You know, there's a lot of different file formats that you can save in, right?
I mean, there's CSV or Excel, but you don't really want them necessarily.
You're doing like native folders, right?
We have Parquet, PyArrow, other better types, right?
So maybe you import some data and you then encrypt it.
So that file sitting on disk, somebody grabs it like, so what?
I mean, your app still has to know the encryption key
and maybe decrypts it in a data frame and memory.
But it's a really nice sort of back and forth library for that, right?
Yeah, and data frames are a perfect place to do that kind of thing.
Prescription tends to be expensive,
but data frames tend to be fairly fast about that kind of stuff.
So you're going to outperform using a mechanism like this
that's built underneath as a Polaris plug-in
than, say, building a loop yourself and doing it.
So it tends to, like you said, it gives you that safety,
but it gives you it in a way that's a little speedier than doing it yourself.
Yeah, I don't remember if I spoke to Richie about this.
Maybe I did, but I don't remember what he said if I did.
That's for sure.
Does Polars do parallelism automatically,
or is there a way to ask it to do it easily, right?
Because this encryption per entry in a column
is one of the embarrassingly parallelizable algorithms, right?
I know there are async pieces underneath.
I haven't played with them myself,
so I'm not sure exactly how you trigger that.
I know, so Polars itself, although it's very much a Python library, the part of it underneath is still Rust.
And I believe that has been built so that you can get some of that concurrency.
I don't know how easy it is to just turn that on.
It hasn't been something, you know, one of the things with concurrency, it's actually what I did my master's degree in.
And the only thing I really remember is really, really don't do it unless you absolutely have to.
And, you know, I routinely ingest a million rows with pollers in a sub-second.
So I've yet to need concurrency because the size of the data stuff that I deal with isn't in that petabyte range where it actually would start to matter.
So there are mechanisms there, but I can't speak to them very well.
Yeah, I haven't done them either.
So time to move on?
Yes, time to move on.
Apparently, yeah, apparently there are ways to do it, but it's not worth going over in audio.
Okay, let's move on.
xdt so sorry yeah i was i wasn't being snarky there i was no no i know
of course this is a date time functionality library uh and it actually comes from the
polars folks so i think what they're kind of doing here is kind of like that contrib thing
inside of django which is yeah we don't really need this we'll keep it separate but if you need
it's there it essentially is a collection i think it's like a 10 or 12 uh functions that essentially
are extra date stuff for example last one was um last commit was by marco corelli who's been on the
show before yeah there you go uh so for example the date range function returns a series of dates
and can be used to populate a column in data frame so it takes a start and end date as arguments and
then will work with a variety of intervals and allows you to ignore weekends and holidays so
if you want to generate like a time series kind of thing, this will do that. The day name function
returns the name of the day of the week, supporting localization. Similarly, there's format localized,
and I think there's other stuff for months and things like that in here as well. The one I kind
of liked, I've done a couple courses on astronomy because a colleague of mine is working on his
degree in this space. And so it always fascinates me when you move sort of sideways in a science and
you're doing what? So this library supports calculating a Julian date, which is kind of
like a Unix epoch, except day one is in 4713 BCE. And although this is fun for history buffs,
it gets used in astronomy so that they can do time lapse calculations as simple addition and
subtraction. And so it's like Julian one versus whatever we're in now, which is Julian 6000
in something. And so if you're as strange as this may seem, if you happen to be working in that space,
this plugin allows you to switch between Julian and back and forth. And then of course, Julian
dates also mean something completely different. So that gets confusing as well, but you know,
welcome to software. And welcome to date times and software for sure. Yes. We have double so in
date time. Yeah. So there's some interesting things here and I have some real time follow
up here in a second. So it says blazing fast written in Rust convert to and from multiple
time zones, which is great, format date time zones and different locales, dueling dates. And then
there's a couple of things that are crossed off and say they've been upstream to polars, which is
really cool. It's like, actually, this turns out to be important enough. It should just be in polars.
So there's this cool interplay here for sure. Yeah, I'm pretty sure this is somebody's playground.
So I think they're maintaining it separately. And I think if it's something that's popular enough,
it'll move up but uh and it is in the github sorry it is in the github uh polars repos not
the organization not just some yeah yeah and that was kind of what i was about to say right back to
your question about sort of a trust thing well the people who write the library when they write
another library to go with it you're probably okay absolutely um marco garelli this my real
time follow-up says hey some of these didn't fit into polars because they would have increased the
size of the binary too much due to extra dependencies right so that's great like too
heavy weight but let's make it an extra so yeah pretty cool that's a good reason to do it yeah
yeah indeed all right let's go and talk statistics a bit yeah what's the chances of that huh so so
from making that from from simple math to harder math yeah uh so let's say you're doing some audio
signal processing and you need to pull some of the frequencies out or you want to try and remove some
noise this process is called filtering one way of doing this is to use something called a least mean
square filter which is a special calculation that tries to minimize the mean square of the error
between the signal and the desired result you too can sound like you know what you're talking about
by reading a wikipedia entry into a microphone so uh if most of what i said was meaningful to you
then the Polars OLS library might be your thing.
This is by Azmi Rajab
and performs least mean squares calculations
using a variety of different mechanisms.
Allows you to do this on at,
it allows you to do this as a Polars expression.
And of course the underlying code,
like a lot of these are as Rust based.
So it's nice and snappy performance wise.
The expression even includes different ways
of dealing with nulls,
which is one of those things
that gets in the way with real world data.
So this library strikes me as one of those things
will save someone a whole lot of time so if you happen to be that someone there you go yeah it's
excellent i you know i think in data science there's a lot of this tension of do i actually
need to know the algorithm and the details of this or do i just need to know that i can call
this function and when i should and when i should call it and i think that's a valid tension right
because if something you call it on the wrong data and you get the wrong answer but you're like
look i've discovered life on another planet oh no i discovered dust or whatever right you know it's
um i was uh doing a bit of tutoring for a friend of mine's daughter a few years back and uh one of
the things i ran into is you know you're allowed to use calculators now which when i was a kid
calculators basically didn't exist and you weren't allowed to touch them but now this is part of the
math program um and one of the things we were talking about a lot is well if you don't know
what answer you're expecting, then when it says a thousand and it was supposed to be
C10, you're not going to know you hit the wrong button.
So I think that's kind of that.
This is exactly what you're talking about.
You need to understand it enough to sort of go, am I getting something back that makes
sense?
But if you just call the function blindly, you know, garbage in, garbage out.
But if you, you know, there's a lot of depth to some of these things and you could spend
an entire career trying to understand it all and that's not going to help you solve the
problem you're trying to solve, right?
So yeah, like you said, balance.
Indeed.
What about pairing?
Okay, so this one's off the charts.
So a pairing function is one that takes two natural numbers
and maps that to a single natural number.
This process can also be undone.
So you can take a single natural number
and find out what pairs could be used to create it.
This is related to set theory and gets into that funky domain
where you can start to talk about some kinds of infinity
are bigger than other kinds of infinity.
The Polars Pairing Library by Antonio Camargo
provides three different pairing functions.
I'm not even going to try.
One of which is Cantor, that one I can pronounce,
which allows you to pair columns in a data frame
or unpair results.
I've got the Sudzik and Hagen as well.
Got them all.
There you go.
If you Google around, you can find all sorts of articles
on what this is and how it gets used in set theory.
how you'd use it in your code is a mystery to me but maybe i just didn't dig enough
uh but if uh if you're mucking around and trying to understand canter pairing why not uh if on the
other hand one of the things i saw come up a couple times with that some of these libraries are often
used as examples for how to write a polars library uh so if you there are certain things you need to
do if you're writing a plugin and so some of these small libraries as much as this might not apply to
your day-to-day, because they're a small library, they can actually be helpful for you to kind of
understand the structure of things because you don't need to understand the math underneath this.
That's just a function call, but you can see the structure of things out there. So sometimes
something like this that is, why would I do that, could actually be a good lesson.
Yeah. Okay. Well, it seems like maybe encryption. I don't know. But yeah,
if you're doing set theory. In theory, this has to do with
hashing in practice i think there are better ways of hashing so um yeah yeah you read it how about
that yeah all right so as a complete aside um there's a several list items on the polar's
package list use the little bear emoji in their docs and i'm not sure if this is just my font
but it looks like a panda and it looks like a panda to me too yeah so so to be clear if polar
bears and panda bears lived in the same place panda bears would be appetizers and they even
come with their own little bamboo garnish. So funnily enough, I'm not sure if this is a strong
signal, but not one of the ones that used the barren emoji was one I could get working on my
system. So I don't know, or whatever that's worth. Anyways, so we kind of got into the weeds there.
So now we'll like step back a little bit and talk about a few things that are a little more higher
level. The Polars List Utils, a good name, kind of describes what it does. This is by Travis
Hammond and it gives you a series of functions that operate on columns that have lists within
the column. So for example, one of the stronger uses here is something called aggregate list
column element wise, which is a long function name, but it does aggregation operations on the values
inside the list data, supporting the same kind of aggregation that regular pollers does. So you
can do a mean account or some or whatever on those things that are in the column. So the library seems
to be coming out of the signal processing space, I suspect, because it supports a whole bunch of
fast Fourier transform mechanisms, including applying them, getting frequency bins, linear
spacing, and all that kind of stuff. The library also has some decent examples in its repo. This
was obviously written by somebody doing something with audio, because there's a whole bunch of sample
data and graph pictures and things like that on it. As a quick aside, this project explicitly
required Python 3.10 through 3.12, but I was able to get it working using the ignore requires Python
flag to pip. So I don't think there's anything, I was using 3.13 and there wasn't anything that
was actually 3.12 specific. So if you bump into that, if you're playing with it, don't worry about
that too much. Interesting. Yeah, probably they just over-constrained their requirements when
specifying the package, right? I ran into it with a couple of the other libraries that I tried out
and they actually didn't work uh this wasn't that case though so this worked fine okay yeah very
interesting and then i hardly believe it i hardly believe it uh i love the image with this one
the nice biker going thing here uh so this is harley this is by tom burge and although the docs
explicitly say it isn't associated with the bikes or the comic there's a nice picture of a motorcycle
in acknowledgement uh and an acknowledgement that this is a port of a pie spark library called quinn
where it comes from. This is a catch-all library. It's got a bunch of different things. So for
example, anti-trim, remove all white space, and single space are all functions that deal with
leading, trailing, multi-white space inside of strings. Approximate equal compares two columns
for equality within a given threshold. So that's kind of useful if you've got a couple floats and
And, you know, if it's within 10% of each other, then that's good enough.
Multi equals checks if multiple columns have a specified value.
So, you know, again, different comparison things.
Div or else divides one column by another, but allows for a default value if the divisor is zero.
So that's useful when you're not supposed to be dividing by zero.
I'm told that's not allowed.
And then there's some validation tools.
It's just a good recommendation.
Yeah.
And there's also some validation tools, Boolean tools, and a few things in here that can help you get information about your schema.
So nice little all told collection.
And I love these kinds of things.
There's a couple of ones in the Django world that there's one I wrote and there's the extensions one as well.
These collections are often I find these are the ones that often save me the most amount of time because there's usually something in them that I'm going to use again.
because this is, you know, it's written by somebody who was trying to solve some problem
and just didn't want to do it twice.
Yeah, very cool.
Yeah, I think, yeah, I think that might be all over.
That's our list.
That's the valid list, yep.
And I was thinking after we went through them, I might know if it were 10 or not,
but I'm even more confused because we went down so many tangents.
I don't even know whether some of them count.
But I can tell you that those are a lot of helpful tools and libraries for people.
So make sure you're putting that list together and doing all the research, Chris.
Yeah, for sure.
And, you know, we only really covered a few of the plugins.
The Awesome Polars list also has links to articles, links to blog posts, things on different interfaces for pollers on other languages that you can use to interact with it.
So even over and above the libraries we talked about there, there's a fair amount of decent content there.
Yeah, absolutely.
All right.
A couple of final calls to action.
I'll let you have the final word but I'll do a few for you check out your Django book very cool
even has some HTMX in it check out your pollers course which I'll link to in the show notes and
is very germane to this conversation and with that people want to do some pollers maybe want to
level up a little bit with some of these things we talked about what do you tell them um you know
it's a very approachable library I think it's uh it's one of those things you can dig in fairly
easily to um not to say hey you know the course is very helpful but the guides that come with
pullers are also very very readable as well um so if you're not if you if you're saving up to take
the course later hit the guides up as well they can be helpful uh and the community seems to be
pretty good i've seen a fair amount of your typical python help each other out kind of space as well
so yeah it's a fun little library and uh very very useful for solving some of your data science
Thanks.
Awesome.
Thank you.
Let me do one more quick little shout out
now that I'm thinking about it at the end here.
Speaking of Marco Garelli,
I had him on recently to talk about Narwhals,
which is a library that will help you bridge code
between working with pandas
and working with pollers and other data frame libraries.
So if you've got some code
and you want to try out pollers on it,
but it's mostly in pandas
or some other data frame library,
like, I don't know, Dask or something,
you can check out Narwhals as well.
And the episode is 480.
so not too long ago.
Anyway, one more thing,
people to help them get started.
All right, Christopher,
thanks for being on the show.
Always fun to catch up with you.
Yeah, great.
Thanks for having me.
Yeah, bye.
This has been another episode
of Talk Python To Me.
Thank you to our sponsors.
Be sure to check out
what they're offering.
It really helps support the show.
Take some stress out of your life.
Get notified immediately
about errors and performance issues
in your web or mobile applications
with Sentry.
Just visit talkpython.fm
slash Sentry and get started for free. And be sure to use the promo code Talk Python, all one word.
And it's brought to you by Agency. Discover agentic AI with Agency. Their layer lets agents find,
connect, and work together, any stack, anywhere. Start building the internet of agents at
Talk Python.fm slash agency, spelled A-G-N-T-C-Y. Want to level up your Python? We have one of the
largest catalogs of Python video courses over at Talk Python. Our content ranges from true
to deeply advanced topics like memory and async.
And best of all, there's not a subscription in sight.
Check it out for yourself at training.talkpython.fm.
Be sure to subscribe to the show,
open your favorite podcast app,
and search for Python.
We should be right at the top.
You can also find the iTunes feed at /itunes,
the Google Play feed at /play,
and the direct RSS feed at /rss on talkpython.fm.
We're live streaming most of our recordings these days.
If you want to be part of the show
and have your comments featured on the air,
be sure to subscribe to our YouTube channel
at talkpython.fm/youtube.
This is your host, Michael Kennedy.
Thanks so much for listening.
I really appreciate it.
Now get out there and write some Python code.
I think is the norm.