Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 51, recorded November 7th, 2017.
I'm Michael Kennedy.
And I'm Brian Okken.
And we got a bunch of awesome Python news lined up for you, as always.
Before we get to that, though, let's just say thank you to Datadog.
Yeah, thanks, Datadog.
Yeah, Datadog is sponsoring this episode.
They've got some really cool sort of whole platform monitoring tools.
And you get a t-shirt if you do their little tutorials.
So we'll talk more about that in a minute.
But now I'd like to explore the United States with some data science.
Yeah, so I ran across this article called Exploring United States Policing Data with Python.
And since that's actually kind of probably a hot topic in a lot of parsing some of that data,
I thought this would be a fun thing to walk through.
So I walked through about half of the paper.
Anyway, but it goes through using Jupyter and IPython and all of those fun tools like Pandas and NumPy to grab some publicly available data.
It's in a CSV file that's zipped.
And you can just import that directly or read it directly with the appropriate tools with a Jupyter notebook and ask some questions like the race of people that get pulled over more often and things like that.
I know it's a very political topic.
I don't really want to get into that part of it.
It is interesting.
But mostly I think it's a very riveting example for walking through why it's important for more and more people to be able to examine public data and be able to figure out what's going on.
Yeah, I think it's really interesting that you bring this up, this example of working with public data.
Like there's a ton of data that we could be asking and answering questions about, right?
This policing data is an example.
Was it fun for you to like play data scientists and play with Jupyter and Matplotlib and stuff like that?
Yeah, it really was.
And one of the things I really actually enjoyed was that the example goes through pretty quickly because it doesn't stop to tell you exactly what all the code does.
It just has the code snippet that you just plop into a Jupyter cell and hit shift enter and it just runs it and plots things.
And I know I can look that stuff up later.
There were a few gotchas that I ran into that I'll put in the show notes.
Since this was my first time playing with Jupyter, I didn't really know that you had to hit shift enter, but I remember hearing that from somebody else to get it to run.
Yeah, it's kind of its own world, but it's really nice.
Yeah, but the example really does start with just from the beginning.
If you've never run it before, you can walk through some of this.
It's pretty cool.
There's some really interesting stuff you can do with police data and data science.
I don't remember exactly the details, so just take this as kind of a general idea.
But I think partially derivative, they had someone on talking about analyzing this kind of stuff.
And it was something like when there was some kind of complaint or episode of violence involving police, it was pretty frequent.
And it was like that the policeman involved in that violence had previously somehow just come off of some other horrible thing.
Like policemen who went to like check on a tech to deal with a suicide and then pulled somebody over who was, you know, noncompliant was much more likely to have a violent interaction with that person at the traffic stop.
So you can do things like say, well, let's change our policy so that people who just had some traumatic event get the rest of the day off so they can process that.
Right.
I mean, these are really powerful and important things.
One of the things I want to caution people for is, is I like I'm a I'm clearly an amateur data scientist because I just did this one thing and just followed a tutorial.
But now you have that title.
Yeah, no, but but there is.
Be careful when you're drawing when you draw conclusions and plot things and show charts.
Suddenly it looks more legitimate.
And yes, there's there's good information you can find, but there's also you got to be careful as well.
So at the beginning in this article, for instance, not all the data is filled in for all police stops.
So you have to deal with like fields that are empty.
What do you do with that?
And this article deals with it by just throwing them away, like throwing away a bunch of it picks one field and says, well, I can fill that one in.
But the rest of them, rest of the rows, if there if there if there's any empties, just throw them away.
I don't think that that's valid.
And I think there's a probably a better solution.
But but I think that if you're going to publish something, you should discuss what you what you did to clean up the data also.
One of the things we've talked a lot about here on the show is performance.
Sometimes that performance comes in terms of asynchronous programming when you're waiting on the network and things like that.
Or other times, maybe looking at things like PyPy.
So most people know there's all these different implementations and runtimes for Python.
But if you're a new listener, maybe new to Python, we have CPython is what most people mean when they talk about Python.
We also have a JIT just in time compiler version of Python called PyPy.
We have IronPython.
We have Jitthon.
We have Cython.
There's all these different variations.
So one of the ones that promises to take basic working Python code and make it a lot faster is PyPy.
So you'll hear people talk about, hey, you could make your code five times faster with PyPy under, you know, a whole bunch of constraints.
So the show, the thing I want to talk about this time on this show is how somebody went and took their code for IoT stuff and made it 80 times faster with PyPy.
Yeah, that's incredible.
80 times.
Yeah.
And I don't think they even really changed the code much.
They did change one little bit of an inner loop, but that was about it.
All right.
So here's the deal.
This person was working on evolutionary algorithms, which they were trying to create basically a self-learning adjusting algorithm that could evolve a logic to control a quadcopter.
Oh, nice.
Right?
Like one of these drone things.
It was a simulated one, but, you know, it could be hooked to a real one.
It didn't really matter.
And in order to drive the quadcopter, this object had to basically run a certain operation every, you know, so often.
And the so often is like 100 times a second.
So quite often.
And they would input this numpy array.
They would do some processing on it and output another one, like how much thrust goes to each motor and things like that.
So this is happening 100 times a second.
And they ran it with CPython.
And their test that they ran, not just once, but a whole bunch of operations, it took about six seconds.
And they said, okay, well, let's try PyPy.
I heard making, you know, using PyPy makes it faster.
So they just sort of typing Python space my program, they type PyPy space my program.
And it turns out it was, wait for it, five and a half times slower.
Oh, no.
That's not faster.
Exactly.
It's like, oh, who sold me this bill of goods, man?
I thought this was supposed to be faster.
So it turns out that the integration with numpy, which is what they're using, actually some of the C interops,
stuff is quite a bit slower.
So they actually use this PyPy implementation of numpy.
It's called numpypy instead of numpy.
And that worked.
That made it faster.
So now it was two times faster just by switching out the imports in the library.
So that's pretty good.
I said, but you know, we actually think we could do better.
And so what they did is they started profiling it and they looked at where it was slow and said, you know, this thing, actually, we could just rewrite this algorithm just a tiny bit.
So it's more friendly to the JIT compiler.
And they got it to go 80 times faster than the original CPython plus numpy version.
No, that's nice.
That's awesome, right?
And that was even 35 times faster than the native PyPy plus numpypy version.
So I think that's a really interesting lesson.
Yeah.
Nice use of profiler, too.
Yeah, exactly.
That's the point I was going to make is like, yeah, it's one thing to throw PyPy or some other technology at it.
But it's not always just going to be like this silver bullet that solves your problem, right?
But PyPy plus a little intelligent problem solving, like that made a huge difference for these guys.
Yeah.
So, I mean, you said this was a simulation?
Yeah, they're doing it as a simulation.
Okay.
I wonder if you can run, I don't know whether or not you can run PyPy on a little tiny quadcopter controller.
I guess it depends on your definition of tiny.
Like if it's raspberry pie, I think you probably could.
If it's eight of fruit size, maybe that might be too small.
I actually don't know.
Okay, cool.
Yeah.
So the next one is an interesting one I saw go by and I saw that you picked here as well.
It has to do with the longevity of open source projects.
Yeah.
This is actually a Wired article called Giving Open Source Projects Life After a Developer's Death.
And I hadn't really thought about that too much before.
But there is, I mean, we've got more and more, as the article goes on, we've got more and more critical projects using open source projects.
And there's a lot of them that don't have that many maintainers or sometimes just a handful or one.
So really, how do you deal with that?
So part of the article is just talking about this as a problem.
But then also there's possibly some solutions.
And I was just wondering if we had any solutions.
I also had some terrible puns I was going to try to throw in.
What to do after you hit your corporeal seg fault and raise an end of life exception.
Yeah, it's definitely something that people, I guess, really want to think of.
I mean, if you're in a business, they do talk about the, like, what if so-and-so gets hit by a bus?
Right?
Will that kill the business?
Well, if this open source project is used by many businesses, it could be that that actually kills a lot of projects, a lot of companies.
Yeah, so I didn't know this was out there.
Apparently, there's a place called libraries.io that has a bus factor evaluator for different libraries.
So you can plug in a library that you depend on and look up its bus factor.
Oh, really?
Yeah, how many of the core developers would have to be on a bus that got hit before the project went away.
But one of the things that it did bring up, which I looked up some of the Python stuff, and some of them are core things that even though there's a handful of maintainers, I think it would get picked up anyway because it's part of the standard library.
But there's definitely others that are of concern.
And one person points out that perhaps we could build some more things into, like, GitHub or PyPI or other places to have maybe errors put in place.
So you could say, you know, if I don't check in for like six months, then transfer ownership to these people or something.
Oh, that's a pretty cool idea.
Almost like an escrow for open source.
Yeah, like, I mean, if you get a big investment account, you got to list who gets it if something happens to you.
So maybe something ought to be like that for open source projects.
That sounds like projects somebody could create and integrate with GitHub.
Yeah, maybe.
One of the other solutions that I have seen is, like, the pytest community for a lot of the plugins.
Try to encourage people to, once you get quite a few users of your plugin, to push it over to a development group on GitHub.
And then anybody on the group can maintain it if necessary.
Yeah, that makes a lot of sense.
I mean, you could always, like, fork the repo and just say, the real one is here.
But I can just see a lot of skirmishes around, like, no, your fork is not real.
My fork is real.
Like, you know, people could fight over ownership, right?
Yeah, and that's doable on GitHub, but you can't really do that on PyPI that I know of.
I don't know how to get transfer ownership on PyPI.
Yeah, I think you got to contact them directly and just lobby your case, right?
Which doesn't sound like a great long-term, widespread solution.
I don't have that problem currently of having any super popular packages, but, you know.
Yeah, that's cool.
Definitely worth thinking about.
Yeah, so before we get to the next topic, let me tell you about Datadog, right?
So performance and bottlenecks, these don't just exist in just your application code, right?
Like, just because your code is slow, well, you could be waiting on the database.
The database could be waiting on some Linux internal behavior.
Who knows, right?
So these are layers upon layers upon layers across systems that we really build our apps with.
And Datadog lets you view all of those as, like, one whole thing.
So let's say you have a Python web app running on Flask.
It's built on Mongo, hosted on a scaled-out set of Ubuntu servers, running Nginx and Michael
Whiskey.
Datadog will let you, like, view and monitor all those things.
It's like one system.
So that is really, really super awesome.
And the more you scale out and the more diverse your system gets, the better Datadog can help
you.
They got a getting started tutorial.
Just take a few moments.
And if you finish it, they'll send you a sweet Datadog t-shirt.
So check that out at pythonbytes.fm/Datadog and see what you've been missing.
I still have to do that.
I need that t-shirt.
Yeah, we got to get our t-shirt.
So maybe this is the wrong season here in the Northern Hemisphere.
Maybe this is going to resonate a little more with our Australian friends.
But this next project I want to talk about is a solar-powered, internet-connected lawn sprinkler.
Oh, nice.
Yeah.
So Lennon, one of our listeners, friends of the show, sent this in and said, hey, I created
this really cool project.
And I'd like to share it with everyone.
I thought, yeah, this is actually a really neat example.
So I thought we'd throw it in here.
And the idea is he went and got this little tiny Adafruit feather huzzah board.
And this is like a little tiny microchip type thing.
But it has Wi-Fi.
So that's important.
You can plug it in somewhere and talk to it.
And it works with MicroPython.
So MicroPython is the Python that works in the smallest devices.
Like you said, the PyPy before.
I'm not sure if you can get PyPy to run on this one.
But MicroPython is so super level.
It basically is the operating system.
Your app is basically the operating system.
Yeah.
So you can take like a Lambda function and connect it right to a hardware interrupt directly.
Like that's how low level.
That's insane, right?
Oh, that's nice.
Yeah.
Right?
And he combines a couple of other interesting things.
He combines Home Assistant, which is the biggest home automation project in Python.
Like a really cool app that integrates tons and tons of different IoT and smart home things.
And he gives a really nice list of like, here's every single piece of hardware I used.
Here's the solar board that I used.
Here's the container for the feather huzzah board.
And it's just a really nice example of a small, compact IoT project.
Yeah.
And useful and not creepy.
I like it.
Yeah, exactly.
The more we seem to go back and forth on these little IoT things.
I really want to create one of these that goes on my front door that uses machine learning
to determine what type of person is on my front door when they ring the doorbell.
Yeah.
Or a dinosaur.
Yeah.
Or a dinosaur.
That's right.
Yeah.
And also I had to put a link in here to Talk Python episode 108
where I actually had the guys from Adafruit come on and talk about a whole bunch of these
different projects.
But yeah, nice job, London.
This is a cool one.
Yeah.
And shout out to Adafruit too for doing all sorts of cool stuff with hardware and software.
I like that.
Yeah.
They have a big educational aspect to them.
Not just education, education, but teaching people who want to learn about IoT.
I'm definitely planning on playing with some of these little devices in MicroPython.
It just seems really fun.
Okay.
So I am going to be perfectly honest with this last one.
I had a...
My last thing I was going to talk about was going to be another packaging story, but I
kind of went down a rabbit hole.
So instead of getting into that, that's my homework for next week.
So I've already set up what I'm going to talk about next week.
But what I want to highlight is some books that came out.
So we had some new Python books that came out recently.
It's a big week for Python books.
Yeah, we've got Python Tricks from Dan Bader.
That came out.
And Matt Harrison's Illustrated Guide to Python 3.
And I have just...
Actually, I'm going to read, at least peruse both of these.
I've just started Python Tricks, and I like the format.
It's cool.
And then I'm going to take a read for Matt Harrison's book.
And the cover is awesome.
And I want to try to get...
Actually, I want to have that around my office so that other people can...
Can look up Python 3 stuff pretty easy.
That seems really nice.
I looked through it as well.
And the illustrated aspect is cool on Matt's.
So yeah, congrats both to Dan and Matt on this.
This is cool.
Yeah.
And then the last thing is that I was on Twitter.
We were...
I was talking with a handful of people, authors.
There are some Python books out there that really could use some Amazon review love.
So I'm going to drop a link to my book and Harry Percival's Test Driven Development, which has been out for a while, but it's still...
It's only got six reviews.
And I know a lot of people have read this stuff.
And then also...
Yeah.
Harry's book is really great.
Obey the Testing Goat and all that stuff.
And then also the Greenfields, Two Scoops of Django.
I know a lot of people have started Django or gotten a lot better at it using this.
So go out and show some Amazon love to these people.
Yeah, definitely.
I think it really helps if you've read a book to write a review.
If you've taken a class, give a review, right?
Like these things actually make a big difference.
Yeah, it really does.
And we're all trying to do things the right way and trying to support the community.
So...
Yep.
It's cool.
Awesome.
Well, the last one I want to talk about is...
Sort of harkens back to the first one that you did, the data science space and the Anaconda
distribution.
So you probably know Anaconda distribution is an alternate distribution for Python.
It's basically CPython.
But instead of just being a standalone CPython where you pip install stuff, it comes packaged
with most of the machine learning, data science, and popular libraries you already need pre-compiled
for your machine.
So if you want to use some weird package that requires like a Fortran compiler or something,
you can just, you know, install it.
Either it's come with Anaconda or you can't install it and it actually downloads the binary
version.
So there's no worries about it, you know, not installing correctly.
Yeah, there's also the free distribution.
There's both paid and free distributions.
But even the free one is one of the few multiple package distributions that is completely legitimate
to do within a company as long as you're not reselling that itself.
Oh yeah, that's awesome.
So the news about Anaconda distribution is version 5 is released.
So they have 100 packages have been updated or added.
They have JupyterLab, Alpha Preview included, updated MKL.
Nice.
That's the Intel high performance compiled stuff.
So it used the Intel sort of low level speed ups for the machine learning and computational
stuff.
New compilers for macOS and Linux.
So what is that?
That's Clang and GCC respectively.
But what's important here is they flipped the flags on the compile steps for all of these
things to use the most newest and compatible flags for security.
So the stuff that gets compiled out of here is less likely to suffer from things like buffer
overflow sort of attacks and stuff.
So that's really cool.
The compilers are now a little safer for you.
They've got updated Condoforge and some other things.
They're creating another channel that has to do with this new compiler thing I talked about
and so on.
So pretty cool.
I still have on my to-do list to go check out JupyterLab.
Have you done any of that?
I have not checked out JupyterLab.
Okay.
It looks fun.
Yeah, it definitely does.
There's a lot of cool stuff happening with Jupyter and like social coding and stuff these
days.
It's exciting.
Well, that's it for my news this week, Brian.
Anything else you want to add?
I did find out last week that the Python testing with pytest is available on, what is that
thing?
Safari Books Online?
Yeah, Safari Online.
It's now there.
That's awesome.
Tons of people have that as just available to them as part of their company, right?
So people can now get your book that way.
I don't think I do.
I'm going to check it out.
Yeah, people can check it out.
I have no idea how if any of that money comes back to me with that, but I'm glad that a lot
of people can read it.
I think one of the things that's great about creating something like a book or a course
or whatever, even a podcast per se, is that people just use it and enjoy it, right?
You put a lot of energy to creating it.
And if it just sat there like digitally silent, that would be sad.
Yeah, it would be.
So cool.
Yeah, I'm glad it's out there and yet another channel for people.
All right.
Well, Brian, thanks again.
Thank you.
for everything this week and talk to you all later.
All right.
Bye.
Thank you for listening to Python Bytes.
Follow the show on Twitter via at Python Bytes.
That's Python Bytes as in B-Y-T-E-S.
And get the full show notes at pythonbytes.fm.
If you have a news item you want featured, just visit pythonbytes.fm and send it our way.
We're always on the lookout for sharing something cool.
On behalf of myself and Brian Okken, this is Michael Kennedy.
Thank you for listening and sharing this podcast with your friends and colleagues.