Latest / Talk Python To Me / #204: StaticFrame, like Pandas but safer
Transcript
- 0:00Remember back in math class when you'd take a test?
- 0:02It wasn't enough to just write down the answer.
- 0:04What's the limit of that infinite summation?
- 0:07Pi over 2.
- 0:08Yes, but how did you get to that number?
- 0:11Some problems in programming are just like this.
- 0:13We want to keep track of the computations done
- 0:15and only add more steps to the results.
- 0:18Heck, that's basically the entire premise of functional programming.
- 0:22On this episode, you'll meet Christopher Ariza,
- 0:24who created a project called Static Frame.
- 0:27Think of it like pandas in NumPy,
- 0:29but it never changes the computations it's already performed.
- 0:32It just adds to them.
- 0:33This is Talk Python To Me, episode 204, recorded February 7th, 2019.
- 0:39Welcome to Talk Python To Me, a weekly podcast on Python,
- 0:55the language, the libraries, the ecosystem, and the personalities.
- 0:58This is your host, Michael Kennedy.
- 1:00Follow me on Twitter, where I'm @mkennedy.
- 1:02Keep up with the show and listen to past episodes at talkpython.fm,
- 1:06and follow the show on Twitter via at Talk Python.
- 1:09Chris, welcome to Talk Python.
- 1:10Hi, Michael. Glad to be on the show.
- 1:12Yeah, it's great to have you on the show.
- 1:13You have a really interesting library that you've been working on,
- 1:17and it's an interesting sort of data-safe take on the whole Pandas API,
- 1:22which I think is going to be a lot of fun for all the data scientists
- 1:26and other people working with pandas out there.
- 1:28Great. I look forward to talking about it.
- 1:29Absolutely. But before we do, let's get started on your story.
- 1:33How did you get into programming in Python?
- 1:34Sure. I started programming in Python in the year 2000.
- 1:38I was a graduate student at NYU, and I was doing a lot of work in computer music
- 1:42and algorithmic composition specifically.
- 1:45And I was looking for a way to extend my capacity, you know,
- 1:51with these very high-level synthesis languages that I was using.
- 1:55So I decided to learn programming in more depth.
- 1:58And I was a graduate student there, so I took a course in C programming.
- 2:02And I had a graduate advisor who was supposed to oversee my work at the time.
- 2:07And I had this great idea to build this system in C.
- 2:10And so I sat with this advisor, and I was like,
- 2:12I really want to do this thing in C.
- 2:13And he said to me,
- 2:14well, if you wanted to build a car, would you start by building every screw?
- 2:18And I said, no.
- 2:20And so he said, use Python.
- 2:22And I was like, what's Python?
- 2:23He said, it's this new great language.
- 2:25Go try it out.
- 2:26And so I walked over to Barnes & Noble in Astor Place in New York City,
- 2:31back when there were bookstores at Barnes & Noble.
- 2:34Yeah, they used to have a great computer section, right?
- 2:37You could go and browse and see what was interesting.
- 2:39That was a way you learned about stuff, and not so much these days, right?
- 2:42Yeah, exactly.
- 2:43Yeah, so you went over and got this book, yeah.
- 2:45I got Learning Python, actually.
- 2:46There was a version of Learning Python out in the year 2000,
- 2:50and I picked it up and started Learning Python,
- 2:52and started building a system I called Athena CL.
- 2:54This was a tool for algorithmic composition,
- 2:57closely tied to a synthesis language called C-sound,
- 3:00and did a bunch of work in that, culminating in my dissertation.
- 3:03Wow, that's really cool.
- 3:04So your dissertation is music and algorithmic composition, basically?
- 3:09That's right.
- 3:09Okay, so cool.
- 3:11So when you started working on this library,
- 3:12and you were doing the programming around it,
- 3:14was this to have the computer generate music,
- 3:19or try to use the computer to understand music?
- 3:21What was the goal there?
- 3:22I was studying, I was getting a PhD in music composition and theory,
- 3:26and so I was using these synthesis languages
- 3:29that took text-based input of event data.
- 3:32So C-sound is an ancient, well, it's not ancient,
- 3:35but it's a very old synthesis language.
- 3:37In computer terms.
- 3:38Yeah, well, it actually comes from an ancient lineage.
- 3:41It comes from the very first synthesis languages
- 3:44that Max Matthews invented in Bell Labs in the 60s.
- 3:48Wow.
- 3:48Called Music 1 and Music 2 and up to Music 5.
- 3:52Those happened at Bell Labs in the 60s and 70s.
- 3:54And C-sound is the modern version of that.
- 3:57And it takes basically a text input file
- 4:00defining your events and your parameters.
- 4:04And it became quite clear that you could do really cool things
- 4:07if you could use code to generate these text input files.
- 4:10And of course, it's quite straightforward to do in Python.
- 4:13So I wasn't using Python to do synthesis.
- 4:16I was using Python to generate control data
- 4:18that I would then feed into C-sound.
- 4:20Okay.
- 4:20How interesting.
- 4:21Have you seen some of the programmatic generated music
- 4:26that people are doing with Python lately?
- 4:28I'm not sure.
- 4:29Is there something specific you're thinking of?
- 4:30Yeah.
- 4:31There's been a couple of presentations around...
- 4:33Gosh, I wish I could remember the library.
- 4:35But there's a couple of libraries that you can use
- 4:37to basically live in the REPL program out songs
- 4:44and interactions.
- 4:44And yeah, it's pretty wild.
- 4:47So maybe I'll find a link and throw it into the show notes
- 4:49because I can't remember the name.
- 4:50But there's been a few really good conference presentations
- 4:52that are basically live musical performances
- 4:54done by programming Python.
- 4:56I think I saw one at PyCon last year.
- 4:59I believe that one worked on top of the SuperCollider language.
- 5:02So SuperCollider is a synthesis language
- 5:04that's much more modern than C-sound
- 5:07that has a synthesis server independent from the language.
- 5:11And it's possible to use other languages to control the server.
- 5:14So I haven't been following it too closely,
- 5:16but I suspect that some people are using Python
- 5:18to control the SuperCollider server,
- 5:21which is a great idea.
- 5:22Yeah.
- 5:22It's definitely interesting to see.
- 5:24I'll throw in the video for people
- 5:25because if you haven't seen it, it's pretty creative.
- 5:27All right.
- 5:28So today you're not doing that much music theory, right?
- 5:31You're working in a different discipline.
- 5:32Tell us about what you do day to day.
- 5:34I worked in academia for a while at a few places
- 5:36and was continuing to do my work in algorithmic composition,
- 5:40generative music, that sort of work.
- 5:41But, you know, decided to look for something else
- 5:43and found a job at a firm called Research Affiliates.
- 5:46We're a finance firm.
- 5:48We define and build strategies for investment
- 5:52that we license to many parties around the world.
- 5:54That's cool.
- 5:54Is this like the so-called algorithmic trading type of stuff?
- 5:57Essentially, our strategies are,
- 5:59many of our strategies are what we call passive investment vehicles,
- 6:03which means that there is an algorithm,
- 6:05a specific procedure that's used to generate
- 6:07the portfolio constituents and the weights.
- 6:10Our strategies are fairly slow moving.
- 6:13It's not high frequency trading.
- 6:14It's not anything like that.
- 6:15Yeah, you're not looking for sub-millisecond advantages.
- 6:18You're looking for just applying algorithms to long-term investing.
- 6:23That's right.
- 6:24All right.
- 6:24So if like Warren Buffett were a programmer,
- 6:25he might be doing stuff like that.
- 6:27Yeah, that's right.
- 6:28I guess.
- 6:29It's funny.
- 6:30All right.
- 6:30Cool.
- 6:31So that brings us sort of full circle back to this idea of pandas
- 6:37and your variation, your take on a slightly different library
- 6:41that is pandas-like.
- 6:43So pandas also comes from the whole finance space, right?
- 6:49Like it's very popular in data science,
- 6:52but of course, you know, it originated out of finance,
- 6:55which is maybe one part of data science, I guess, right?
- 6:57Maybe.
- 6:58I see data science as,
- 7:01and there's certainly discussions and presentations on this issue,
- 7:04I see it as, in some ways, more speculative research into data.
- 7:09As opposed to using these tools for the systematic application of an algorithm or a procedure.
- 7:14Right.
- 7:14So what you're thinking is more that like what you guys do day to day is more programming,
- 7:19using these tools that maybe originated out of data science,
- 7:23but you're deploying production systems that are running and doing stuff,
- 7:27not so much coming up with graphs and inferring stuff with Jupyter.
- 7:31Yeah, exactly.
- 7:32Right.
- 7:32Okay.
- 7:33Yeah.
- 7:33But at my firm, we have finance researchers who that's what they do.
- 7:37They comb over data and study research and, you know, try to make observations from the data.
- 7:42You know, that is closer to data science.
- 7:44But by the time strategies come to us, they are well-defined.
- 7:48So we are, you know, implementing the production strategy
- 7:51and don't really have that sort of discovery exploration need.
- 7:55Okay.
- 7:55So let's maybe start from the beginning.
- 7:59You told me the idea of building these strategies and you've created this library called Static Frame,
- 8:05which is really interesting.
- 8:06We're going to talk a lot about it.
- 8:07But you started with Pandas, right?
- 8:09You're like, let's use Pandas and other Python libraries to solve this problem
- 8:13before you decided I'm going to replace Pandas with my own library, right?
- 8:16Yeah, that's right.
- 8:17Maybe talk about that journey.
- 8:18Sure, sure.
- 8:18Well, actually, when I started at Research Affiliates in the year 2012,
- 8:23Pandas was still quite young at that point.
- 8:27And my predecessor had created his own library to model data transformations
- 8:34and basically storing data in a table and then efficiently being able to add new data to that table by column addition,
- 8:42kind of an Excel-like data model, but implemented in Python.
- 8:46And his implementation was very straightforward.
- 8:48It was simply a dictionary that held rows where the rows themselves were a dictionary.
- 8:54So kind of like a JSON representation of a table, if you will, a dictionary for the rows and then a dictionary for each row.
- 9:02And there, of course, we weren't using NumPy as the back end, but it was actually reasonably efficient.
- 9:08And we still use it in some places.
- 9:11After about in 2013, we started to, I spent some time looking at Pandas and started to use it because, of course,
- 9:18the underlying performance in large part due to NumPy and being able to use the vector operations of NumPy
- 9:25gave a significant advantage over using our own table model.
- 9:29Yeah.
- 9:29There's such an advantage to using things like NumPy where you hand a little data off to the C layer and that layer can do all the computation.
- 9:37There was a really interesting analogy or observation made by Alessandro Molina from the last couple episodes ago.
- 9:44And he was talking about Python is one of these languages that is a little bit counterintuitive.
- 9:50Like in C, if you want something to go really fast, you might make it go really fast by writing and implementing the details in C or some other language.
- 9:57And so the more you can kind of control that, the more precise you can be.
- 10:01Where Python gets faster, the more high level you try to treat it.
- 10:05So if you tried to implement those algorithms in pure Python, they'd be slow.
- 10:08But if you just call like a high level NumPy function, boom, it's fast, right?
- 10:13And so it's like this sort of inverted understanding of like where the performance is in this language compared to others.
- 10:20Yeah.
- 10:20And, you know, I have to admit, I had looked at NumPy before.
- 10:24I'd been using Python for a long time.
- 10:26But the context of using it through pandas as a wrapper to NumPy really started me thinking, oh, when I want to scale a vector, I just multiply by the value.
- 10:38And I scale the whole vector.
- 10:39And this happens amazingly fast.
- 10:41And there's no loops.
- 10:41And you begin to take on that mindset that wherever you have a loop, you're doing something wrong.
- 10:46You know, you want all your loops to be in the NumPy layer.
- 10:49And it takes a bit of conceptual work to get there.
- 10:52Yeah, that's such an interesting observation.
- 10:54I definitely think that that's true.
- 10:56And you want to let it do that for you.
- 10:58But to think, oh, there's a loop.
- 11:00Where are we missing the opportunity to make this work the way pandas and NumPy should?
- 11:05Yeah, absolutely.
- 11:07I mean, yeah, that's exactly in our team code reviews.
- 11:11That's exactly one of the things that we sort of look out for.
- 11:14We see, you know, I see some pandas code that somebody wrote.
- 11:16And I see a couple loops or a loop in a loop.
- 11:19And I'm like, oh, there's got to be a better way.
- 11:21Quote Raymond.
- 11:22Yeah, absolutely.
- 11:24There's got to be a better way.
- 11:25That's cool.
- 11:26All right.
- 11:27This transition over to NumPy and pandas, this was pretty successful, right?
- 11:30Like you guys were able to replace that library and do more of your work in these libraries and these packages?
- 11:36Yeah, that's right.
- 11:37We didn't entirely replace it because the old table model worked reasonably well in a few cases.
- 11:41But in implementing some new strategies, some new tools, I started working with pandas.
- 11:46And it's funny because although you have a bunch of utilities on pandas, it's hard to figure out what to do with it or how to use it, really, I think.
- 11:54But I already had a precedent.
- 11:55The precedent I had from our old library was that you start with data in a table.
- 12:00You load up initial data, initial observations about companies, for example.
- 12:05And you may maybe have 40 columns on a table of 10,000 companies.
- 12:10And that's your initial inputs.
- 12:12And then you add new data by doing operations, applying functions on those rows or previous columns and add new columns.
- 12:20And the previous library we used was actually very much aligned to that workflow.
- 12:25So moving to pandas was actually quite smooth because pandas very easily supports growing a data frame by adding columns.
- 12:33And those column additions can easily be performed by doing operations on columns that are already on the table or doing function application to rows already in the table.
- 12:43That makes a lot of sense.
- 12:43We discussed this a little bit before.
- 12:46You talked then about how it was really important as your data flows down the pipeline that is doing all the calculations and eventually comes to a decision of invest in this, not in that, or this much in that area to keep a history and keep track of what's happening.
- 13:05Right?
- 13:06Yeah, exactly.
- 13:07That paradigm was established before we ever moved to pandas.
- 13:10And it was a large part of the approach and ethos of my company and how we do our work.
- 13:15Our strategies are not black boxes.
- 13:17We don't use esoteric machine learning to discover results.
- 13:22We use very explicit approaches that we want to be transparent.
- 13:26And we do human quality control on everything that we release.
- 13:31So it's my obligation to expose as much of the internal calculations as possible.
- 13:38A lot of the intermediates, values, groupings, labels, everything that is necessary for a human to understand.
- 13:45The calculation we try to expose in our final output.
- 13:49So the table becomes initial data first as 20 or 40 or more columns as your initial data.
- 13:55And then numerous columns that are intermediate calculations, intermediate results, reducing the opportunity set through screens and some other processes.
- 14:04And then finally getting to the actual result, which in our case is weights and constituents.
- 14:11Yeah.
- 14:11It sounds very inspired by what you almost might do in Excel or Google Sheets.
- 14:16Right?
- 14:17You have your data and then you create a formula here.
- 14:20And then that female formula is based on that previous one.
- 14:23But you would never go and like replace the original data and change it with a formula in like some weird iterative way.
- 14:29It's always just kind of like to the right and down.
- 14:31That would be disciplined use of Excel.
- 14:34Unfortunately, there's no discipline inherently in Excel.
- 14:40So you see all sorts of things.
- 14:41Yeah, that's true.
- 14:43That's true.
- 14:43But, you know, I guess inspired at least by the proper use.
- 14:47So that's pretty cool.
- 14:49So you did all this in Pandas and that was working really well.
- 14:51Why create a new library?
- 14:53Like what were the pain points or what were you like, you know, if we redesign this to be Panda-like but not Pandas, what could you gain?
- 15:01Right.
- 15:01The initial inspiration was, you know, recognizing this workflow that we had where we would start with initial data and some columns and then add columns as we go.
- 15:11That initial workflow, we found that it worked really good and it was relatively safe as long as you followed this sort of grow-only paradigm where the table only gets bigger.
- 15:24Yeah, exactly.
- 15:25Exactly.
- 15:26Yeah.
- 15:26So that's the discipline that we were doing implicitly.
- 15:30But we started to speculate, well, you know, it would be really nice if we could actually enforce this grow-only paradigm and in doing so remove a lot of opportunities for error.
- 15:40Now, by convention, we would never mid-process go and update in place a value we had already used.
- 15:48But we were certainly sensitive to that danger and in particular for teaching our paradigm to new members of our team and the rest.
- 15:56We had this strong desire, oh, it would be so great if we could sort of enforce in some way this grow-only paradigm.
- 16:03And that led naturally to thinking, well, what if the frame data itself could be immutable?
- 16:09More than just enforcing a grow-only paradigm, what if you had immutable frames?
- 16:13There's places where we open up a – we use a table as a reference data set and we might bring that in as a data frame.
- 16:20So I might bring in FX rates, currency conversion rates as a series indexed by currency code and the currency conversion value.
- 16:29And that's a reference value that I'm using in many, many, many places.
- 16:33And the opportunity for error if any of those values gets mutated is significant.
- 16:37So we kept on coming back to this.
- 16:40Like, it would be so great if we could freeze a series or freeze a table like we have frozen set, for example, and treat it as a immutable collection.
- 16:51Yeah.
- 16:51And, of course, it completely simplifies the whole debugging and validation, right?
- 16:57Because you no longer have to look for these weird references where somebody still has a pointer to the data frame and they call a function that changes the values or, you know, does some other odd thing where they're off by a column index or something.
- 17:13And, you know, it seems like debugging that would be really hard.
- 17:17And, of course, making financial decisions on it might be really bad.
- 17:20Yeah, that's right.
- 17:21It reduces what I often say is it reduces the opportunity for error.
- 17:25There's many ways that you can things can go wrong and you can get very confusing, unexpected results by mutating your inputs and your values as you go.
- 17:35Yeah.
- 17:36There's the safety side of things.
- 17:37And that makes perfect sense.
- 17:39That's probably primary.
- 17:40Another thing that immutable data really opens up, I don't know if this matters at all to you guys, but anytime you have immutable data, you start to have incredible opportunities for parallelism, right?
- 17:53Like if you're sharing it, you don't have to worry about, oh, I got to lock on this and make sure that's not changed.
- 17:57You just riff on it because it's immutable.
- 18:00It's not going to change.
- 18:00Yeah, that's a really interesting potential that I haven't really explored.
- 18:04The one way I have explored it with Static Frame is that our function application iterators expose an interface to multiprocessing or multithreading function application to columns and rows.
- 18:18So I've experimented with a little bit, but there's definitely more opportunities to look out for that.
- 18:23Yeah, it sounds like for sure.
- 18:25And maybe you could even mix in some Cython in there so it releases the GIL for the threaded side of stories.
- 18:31And it just seems like there's a lot of cool possibilities to dig into that.
- 18:34Is performance at all something you care about?
- 18:36Or is it like, it takes two minutes and we run it once a day or once a week, so it's fine?
- 18:40Yeah, definitely.
- 18:41Performance is a very significant concern.
- 18:43And as I was doing this, as I started working on this in May of 2017, and I started very small with this speculation.
- 18:53I wasn't sure if I could do this in native Python.
- 18:56That was the thing is that we, for years prior, me and my team who shared these convictions and these goals, speculated on something like this.
- 19:06And I always thought I was going to have to implement it in C.
- 19:08It's time to build the screws and the nuts and everything.
- 19:10Exactly, exactly.
- 19:11Yeah.
- 19:12So I was going to have to implement this in C.
- 19:14And maybe I'd done some work in C++.
- 19:16So, you know, I was like, maybe I can implement this in C++ and build off the STL vectors.
- 19:21And then I realized, oh, man, I'm re-implementing NumPy.
- 19:25I don't want to do that.
- 19:26And it was after a PyCon, I think it was two years ago, yeah, because it was in May of 2017, something that the PyCon triggered for me that, you know, why don't I just try it in native Python?
- 19:36And if I've hit bottlenecks, I can use Cython, but I should just see what I can do and use NumPy and just use Python.
- 19:43And I set out on that goal, and I found that performance is very good.
- 19:48I mean, I can get in for many operations I can do as well or better than Pandas.
- 19:52Some operations I'm slower.
- 19:54Some operations I'm better or significantly better.
- 19:56The aggregate performance is very hard to measure.
- 19:59It's very dependent on use cases.
- 20:00There's some things that are definitely slower than Pandas.
- 20:03But at this point, it's just pure Python, pure NumPy.
- 20:06We haven't done anything in Cython or C extensions or Numba or anything like that.
- 20:11This portion of Talk Python To Me is brought to you by Linode.
- 20:16Are you looking for hosting that's fast, simple, and incredibly affordable?
- 20:20Well, look past that bookstore and check out Linode at talkpython.fm/Linode.
- 20:25That's L-I-N-O-D-E.
- 20:27Planes start at just $5 a month for a dedicated server with a gig of RAM.
- 20:31They have 10 data centers across the globe.
- 20:33So no matter where you are or where your users are, there's a data center for you.
- 20:37Whether you want to run a Python web app, host a private Git server, or just a file server,
- 20:42you'll get native SSDs on all the machines, a newly upgraded 200 gigabit network, 24-7 friendly
- 20:48support, even on holidays, and a seven-day money-back guarantee.
- 20:52Need a little help with your infrastructure?
- 20:53They even offer professional services to help you with architecture, migrations, and more.
- 20:58Do you want a dedicated server for free for the next four months?
- 21:01Just visit talkpython.fm/Linode.
- 21:05So you're getting great performance out of it already, and then there's all these low-hanging
- 21:10fruit opportunities if needed.
- 21:12Yeah, that's right.
- 21:12Yeah.
- 21:12So it's interesting you talk about the performance and could I do it this way?
- 21:17And I think people, programmers, are really bad at judging what's going to be fast and what's
- 21:22going to be slow.
- 21:24You look at some code, you're like, oh, this is definitely the problem.
- 21:27Maybe it's slower, but it's sub-millisecond and who cares?
- 21:31Or it's actually not even that part.
- 21:34It's something totally different.
- 21:34Did you do profiling and stuff like that to really try to dial that in, or did it just work
- 21:40out?
- 21:40Early on, I started benchmarking against pandas for certain operations.
- 21:43And so I don't think of my...
- 21:46It's actually a huge debt to pandas that they've provided this great framework that does so much
- 21:51and really sets the foundation.
- 21:53Of course, it's descended from R.
- 21:54So pandas inherited a bunch of things from R in terms of the concept of the data frame.
- 21:59And I think compared to what I know of the R model, they refined the interface and unified
- 22:04it in quite a nice way.
- 22:05And in doing so, they've really defined a set of expectations for using libraries like this.
- 22:10One example is the drop NA method on a series or frame, like the idea that given a series
- 22:17or frame, there should be an easy way to remove missing values.
- 22:20We have to do this kind of thing all the time.
- 22:22So with that model in mind, I could start to implement those things and test them.
- 22:26And the performance metric that is relevant to me is my ratio to pandas.
- 22:30So that's what I know.
- 22:31Like I know for this operation, oh, I'm 0.6.
- 22:35I'm faster than pandas.
- 22:36Or for this operation, I'm 10 times slower than pandas.
- 22:38And I do it at this very granular level for one-to-one comparisons.
- 22:43That's a really interesting metric to think about.
- 22:45But I guess it makes sense because you're like, I would like to have this other model, this
- 22:49other data model, this other programming model that's data frame-like that has the safety
- 22:53immutability thing.
- 22:54It used to be pandas.
- 22:55Long as I don't wreck the performance too much.
- 22:58And if there's a benefit, then hooray.
- 23:01Like, we're good.
- 23:02Yep.
- 23:02That's exactly right.
- 23:03Yeah, that's a cool way to think about it.
- 23:05So let's talk about how static frame deviates from pandas.
- 23:10You know, so the overall idea is this immutable data grow to the right sort of story.
- 23:16But there's a lot of details here.
- 23:18Do you want to maybe talk us through them?
- 23:19The biggest insight is, I mean, one of the biggest changes really is the underlying numpy
- 23:25arrays are made immutable.
- 23:26This was one of the key observations that led me to start, you know, developing this and
- 23:30realize I didn't have to write this thing in C or C++ myself in that I found there's a
- 23:35flag on the num.
- 23:36Each numpy array has a flag attribute.
- 23:38And on that flag attribute are a number of properties.
- 23:40One of them is writable.
- 23:42And it's a Boolean.
- 23:43And you can flip it.
- 23:44And in doing so, the numpy, if you try to assign values into the numpy array, it gives you
- 23:49an exception.
- 23:50And numpy arrays, of course, are already fixed in size and shape.
- 23:55They are, numpy arrays out of the box are mutable in terms of the values contained within
- 23:59that size and shape.
- 24:00But when I found this, I was amazed.
- 24:02I was like, oh my God, this is what I've been looking for.
- 24:04So with that insight, I began writing the core piece of the library, which is the internal
- 24:10component called the type blocks, which manages the heterogeneous typed arrays and exposes a
- 24:18unified interface to external clients.
- 24:22So that first piece really of making all the internal arrays immutable and what I describe
- 24:28as fully managing the array.
- 24:30That is, if you create a static frame object with a numpy array, if that array happens to
- 24:37be immutable, I can take it and I can use it and I don't have to make a copy.
- 24:40But if static frame frame is given a mutable array, I make a copy and I make that copy immutable.
- 24:47And from there on, we're safe.
- 24:48Yeah, that's really cool.
- 24:49So obviously, if you're given immutable data, problem solved, right?
- 24:53But if you're not, then you want to take ownership of that data, take it inside of your library
- 24:59and say, yeah, you gave me this.
- 25:01I've read it.
- 25:01Now we have a safe version of it.
- 25:04It's really cool that you were able to just leverage that built-in feature of numpy because
- 25:08that meant that whole layer down there.
- 25:11You could just build on what numpy is doing and not have to go, we're starting from scratch
- 25:16with nuts and bolts, right?
- 25:17Yeah, exactly.
- 25:18And I'm still quite curious why it's there because it's not really advertised anywhere
- 25:24in the numpy docs.
- 25:25I don't see information as to suggestions of using this or whatnot.
- 25:30I found little bits of discussion here and there where I've seen other evidence of people
- 25:33using it.
- 25:34It is certainly documented in the flags as part of the flags for an array, but I'm actually
- 25:39eager to find out more information of how it got there and how the numpy developers imagined
- 25:44it would be used.
- 25:45Yeah, maybe if someone's listening, they know they could come and put a comment on
- 25:48the show.
- 25:48Yeah, that'd be great.
- 25:49On the show page.
- 25:50That'd be cool.
- 25:50We'll all learn from it.
- 25:51Yeah.
- 25:52Yeah, great.
- 25:53So how much having it based on numpy was it, I guess, able to more or less stay the same
- 26:01as before?
- 26:02Like, did it make moving from pandas a lot easier?
- 26:05Yeah, that's right.
- 26:06Because, of course, pandas, at least in its present state, all data is stored in numpy arrays.
- 26:12So basic expectations about how that data would work are the same.
- 26:17Our goal, though, with static frame was to be closer to numpy.
- 26:20And what that means is that every time that we do a calculation, like produce a standard
- 26:26deviation or a mean or something else, we use numpy operations.
- 26:31I feel like pandas is a bit ambivalent about this, and they have probably reasons probably
- 26:36for performance for doing this.
- 26:37But sometimes if you call the STD method on a series, you're not actually executing numpy
- 26:45or you're executing numpy in an unexpected way.
- 26:48I have a lot of respect for numpy's stability and over the years, over their versions.
- 26:54And I trust numpy in terms of their approaches to doing these calculations, their defaults,
- 26:58et cetera.
- 26:59And I don't want to make those decisions.
- 27:00So I'm happy to rely on numpy entirely for those sorts of calculations.
- 27:05And then the numpy type system is something also that pandas has sort of struggled against
- 27:09or is ambivalent about or actually increasingly seem to want to get away from.
- 27:14Rather than try to create or my own type system or augment numpy's types, I took the efficient
- 27:21approach for the resources for the project, which is just, OK, we'll just use numpy types.
- 27:26Which means one very clear way this shows up is that if you create a series out of two
- 27:32character codes, like FX currency codes, three character currency codes, you will get a series
- 27:39of fixed offset Unicode, three Unicode characters, which is what numpy does by default.
- 27:44So whereas pandas will convert that into an object type.
- 27:47So I just let numpy use its types pretty much as it would naturally do and avoid getting involved
- 27:54in that.
- 27:54Yeah.
- 27:55Yeah.
- 27:55And of course, you carry over all the validation and testing to make sure that all the calculations
- 28:00were done as accurately as possible.
- 28:02And that's quite a matter as well.
- 28:04Yeah, that's right.
- 28:04So yeah.
- 28:05So some other things that look like differences for static frame relative to pandas is one
- 28:11is around unique indices.
- 28:12Yeah.
- 28:13So this so there was, you know, there's a couple of things that we as a team would constantly
- 28:18be frustrated with in terms of pandas.
- 28:21And one really obvious one is this ambivalence about whether an index should be unique or not.
- 28:26This is when I think of an index, and maybe most people think of an index, they think of
- 28:30it as a mapping similar to a Python dictionary where keys have to be unique.
- 28:35And very often, that's how people use indices.
- 28:37But in pandas, indices don't have to be unique.
- 28:40And we would constantly be surprised when we found that a column in a table was set as the
- 28:48index.
- 28:48And without us realizing it, those values in that column were not unique.
- 28:53And we ended up with a non unique index.
- 28:55And if you try to select row from a non unique index using an LLC call, where you expect to
- 29:02get a series representing a row, now suddenly you get a data frame representing two rows.
- 29:07And that's very confusing and surprising.
- 29:09Pandas has an option to enforce uniqueness when you create an index from a column with a amusingly
- 29:16named parameter called verify integrity.
- 29:18And verify integrity is by default set to false on pandas set index operation, which I understand
- 29:26the desire to be accommodating, which I think is the motive here.
- 29:30But I do not want to be accommodating.
- 29:33I want to say that an index is a unique collection.
- 29:36And if you try to create an index that of a non unique collection, you'll get an error.
- 29:41Right, you should get zero or one things, not zero one or other numbers.
- 29:46Yeah, interesting.
- 29:47Another one is around dot access.
- 29:49So basically, Dunder get item mapping over to like pulling items out of the by by index.
- 29:55Yeah, and I think this was motivated by the ancestry of R.
- 29:59So in the R language, the not exactly certain, but I believe that our data frame library exposed
- 30:06columns through dot attribute like lookup.
- 30:09And I suspected that in early versions of pandas, there was a big pull to try to move our people
- 30:15over to Python and having that similar syntax, I assume was was desirable.
- 30:20But of course, there's other attributes other than columns on the data frame object.
- 30:24And so inevitably, there's some sort of naming collision that's going to come up with getting
- 30:30columns from dot attribute.
- 30:31So with static frame, we simply say the only way to get a column is by using the get item
- 30:36syntax.
- 30:36And there's no dot access.
- 30:38And that's sort of the general theme of trying to have there be only one and one way to do
- 30:43things.
- 30:43And in terms of getting a column, we say, okay, you use the get item syntax.
- 30:46Yeah, that's, I think that makes sense.
- 30:49You know, you want to be like one of the overriding themes, it sounds like a static frame is sort
- 30:53of safety predictability.
- 30:55Right?
- 30:56Not like, oh, we asked for the load.
- 30:58And that's not the load on the system column.
- 31:00That's the load data method or some weird thing that happens, right?
- 31:04When you interact with it that way.
- 31:05Yeah, exactly.
- 31:06And, you know, of course, it's a huge benefit to have to have pandas.
- 31:10And, you know, there's actually a family of data frame like interfaces around these days.
- 31:15Not only is there the pandas data frame, but I think some other library, I think of Xarray.
- 31:20Xarray has kind of a pandas like thing.
- 31:23And there's a few other libraries out there.
- 31:25So it's just a huge benefit to be able to look at, you know, the hard work of all of these
- 31:30contributors over the years, be in the luxurious position of picking and choosing.
- 31:34And so, you know, it's a great debt we have to those other packages and pandas in particular
- 31:40to be able to look at those libraries and see, okay, I see why they made all those choices.
- 31:44But we can consolidate all that into one thing and remove a bunch of ambiguity, remove a bunch
- 31:49of opportunities for error.
- 31:50Yeah.
- 31:50Does the growth of Python in the data science data exploration space and the popularity of
- 31:57pandas make this an easier sell at your company?
- 31:59Like, do you feel like you don't have to cheerlead and like make the case for Python so much?
- 32:04When you go and talk to people, the management or whatever, say, yeah, we're building it this
- 32:07way.
- 32:08Yeah.
- 32:08Well, in terms of Python in general, the growth and popularity of Python, as I'm sure all of
- 32:13your listeners know, has been extraordinary in the last five, 10 years.
- 32:18And the role of Python in data science is probably largely due to pandas.
- 32:25And I would even go further to say specifically pandas read CSV, which is just extraordinarily
- 32:31fast, blows NumPy, blows everybody else out of the water and is such an awesome thing that
- 32:37I think it's the gateway into Python for data science.
- 32:40Your question specifically about using Python within our firm, it's been a gradual move.
- 32:45My team was the first to use Python, but more and more, nearly every other area of the firm
- 32:50that's doing something with software engineering is using Python.
- 32:53And of course, everybody starts with pandas because that's what you see.
- 32:57Because it's a load CSV.
- 32:58Yeah.
- 32:58Yeah.
- 33:00And the idea with Static Frame was like, well, that's great for data exploration.
- 33:04But if you're going to build something that you want to last and you want to reduce opportunities
- 33:08for error, take what you know from that library and try it out with this thing and see what
- 33:13you can do.
- 33:13That's cool.
- 33:13You said it was basically becoming increasingly popular.
- 33:16What technologies was it displacing?
- 33:19Like what else were you using to the extent you can say?
- 33:21Sure.
- 33:21Yeah.
- 33:21I mean, within our firm, we were using SAS.
- 33:24We were using R.
- 33:25And those were the primary two languages, which are still quite common in finance firms
- 33:29and the like.
- 33:30And to a certain extent, people still use those.
- 33:32But you can see the effort in the Python community, both SciPy, Pandas, NumPy, Matplotlib, many
- 33:40others moving in the last five, 10 years to provide all of that functionality that R had or almost
- 33:45all of it and many other platforms.
- 33:47So it's quite easy transition.
- 33:49Well, not easy, but it's a directed transition from those other languages.
- 33:54Yeah, it's definitely it's not like going from that to C or something crazy.
- 33:58Yeah, for sure.
- 33:59So another difference has to do around iterating static frame, right?
- 34:03And Pandas, when you iterate, you get the values.
- 34:05And here, it's more dictionary-like, right?
- 34:08Oh, OK.
- 34:08Yes.
- 34:09There's two elements to sort of the iteration thing.
- 34:11The first has to do with the static frame series.
- 34:15So the frame and the series and both Pandas and static frame are dictionary-like containers.
- 34:21Both static frame and Pandas define a keys method, define an items method that work in a way that
- 34:28we know well from Python dictionaries.
- 34:31With static frame, the difference, though, has to do with the series.
- 34:34When you iterate a Pandas series, it iterates over the values, which makes some sense if
- 34:42you think of it as a wrapper around a NumPy array.
- 34:44But if you call dot items on a Pandas series, you're going to get pairs of the index, the key,
- 34:51and the value.
- 34:52So again, in this effort to try to be consistent, if you iterate a static frame series, you are
- 34:58going to iterate over the keys, just like you would with a Python dictionary.
- 35:01So you actually get the index values.
- 35:03And if you want to get the values, you have to use the dot values attribute.
- 35:06Right.
- 35:07That's one difference in terms of iteration.
- 35:08The other is, while that dictionary-like interface, we try to be really consistent there, the other
- 35:15place is recognizing that Pandas has a number of different approaches to iterating over columns
- 35:22or rows in a frame and function application on those iterations.
- 35:27So Pandas has an apply function, and it has various iteration functions.
- 35:31Like iter rows or iter tuples.
- 35:33And I saw an opportunity to unify all of those.
- 35:36So the series and the frame all have different families of iterators.
- 35:41And all of those iterators return objects that themselves have function application methods
- 35:47on them.
- 35:47So the same tool you use for iterating exposes an opportunity to do function application.
- 35:52And that descends from the old library that we use, where function application across the
- 35:57table was a really common move.
- 35:59And so making that sort of a first-class element in the library was really important to us.
- 36:04Yeah.
- 36:05It sounds great.
- 36:06Also, you talked about the sorting.
- 36:08The default sorting is stable in static frame.
- 36:12What's the story there?
- 36:13This is very simple because, fortunately, NumPy did all the work here.
- 36:16NumPy's sort method provides a number of options for which sorting algorithm to use.
- 36:22And again, in the spirit of safety and repeatability and stability, the default sort method for static
- 36:32frame is set to pandas merge sort, which is indeed stable.
- 36:36The default for pandas sort is you can switch it to be merge sort.
- 36:40But by default, I forget exactly what it is.
- 36:42But it is not a stable sort.
- 36:45Like quicksort or something like that.
- 36:46Yeah.
- 36:47I believe the default is quicksort.
- 36:49Now, why they chose quicksort, I don't know if there was any reasoning behind it.
- 36:52Maybe quicksort is faster in certain cases.
- 36:54But merge sort is reasonably fast.
- 36:56And if I can make a choice to ensure that the sort is stable to the order entering the
- 37:02sort, that seems like a benefit to me.
- 37:04Yeah.
- 37:04It comes back to this predictability, safety, overriding theme, right?
- 37:09Exactly.
- 37:09Yeah.
- 37:09So I guess maybe another area is how it's tied to the NumPy defaults for calculations.
- 37:19And things like that.
- 37:20Yeah.
- 37:20So that gets back to the spirit of, you know, being close to NumPy.
- 37:24And I have an example of this where, you know, you take the standard deviation of three values
- 37:31without any arguments in with a pandas series.
- 37:35And you get a different value if you do the same thing with a NumPy array.
- 37:40If you use NumPy's STD function, you get a different value.
- 37:43And that's very confusing.
- 37:45And it has to do with the DDOF, the delta degrees of freedom argument to the standard deviation.
- 37:52Now, people that have played with standard deviations are well aware of this parameter.
- 37:54But some people may not be.
- 37:56And that's quite confusing.
- 37:58And I just, I don't see a need for that heterogeneity.
- 38:01I'm fine to stick with NumPy.
- 38:03Yeah, that makes a lot of sense.
- 38:08This portion of Talk Python To Me is brought to you by StellarS, the AI-powered talent agent for top tech talent.
- 38:14Hate your job or feeling just kind of meh about it?
- 38:17StellarS will help you find a new job you'll actually be excited to go to.
- 38:22StellarS knows that a job is much more than just how it sounds in a job description.
- 38:26So they built their AI-powered talent agent to help you find the ideal job.
- 38:31StellarS does all the work and screening for you, scouting out the best companies and roles
- 38:36and introducing you to opportunities outside your network that you wouldn't have otherwise found.
- 38:40Combining deep AI matching with human support, StellarS pairs things down to a maximum of five opportunities
- 38:46that tightly match your goals, like compensation, work-life balance, working on products you're passionate about, and team chemistry.
- 38:53They then facilitate warm intros.
- 38:56And there's never any pressure, just opportunities to explore what's out there.
- 39:00To get started and find a job that's just right for you, visit talkpython.fm/StellarS.
- 39:06That's talkpython.fm/S-T-E-L-L-A-R-E-S.
- 39:11Or just click the link in your show notes in your podcast player.
- 39:14Let's see, another one is discrete functions rather than branching parameters.
- 39:20So like trying to, is that like breaking stuff apart so there's functions that are simpler to understand rather than taking a bunch of parameters?
- 39:26Yeah.
- 39:27We've tried to systematically design an interface that has functions that have orthogonal parameters.
- 39:34So I think when all of us write functions, that should be our goal.
- 39:39That is, the relevance of one parameter to a function shouldn't depend on another parameter.
- 39:44That's quite confusing and can lead to mistakes.
- 39:47What you get instead is more functions.
- 39:49But the functions are more specific.
- 39:51And I believe that leads to more clear code.
- 39:55And it also aids in refactoring, actually.
- 39:58One example of that that I think is nice is the set index method.
- 40:02So on pandas, there's a set index method that if you give it one column as the argument, it will set that one column as an index.
- 40:12If you give that argument a list of column names, it will give you a hierarchical index.
- 40:19And all you did was change your input.
- 40:22And now you have a very different structure coming out of this.
- 40:25Right.
- 40:25Not even necessarily keyword arguments, but you just change the type that you're passing.
- 40:29Right?
- 40:29Yes, yes, yes.
- 40:30So there's many places in pandas where there is this sensitive dependency to the type of an argument that results in a different output, which is very problematic.
- 40:40So in static frame, we have two methods.
- 40:42We have set index, and we have another method called set index hierarchy.
- 40:46And when you set index hierarchy, there you're expected to give an iterable of column.
- 40:51And you can't give it a single column and vice versa.
- 40:54So we split the functionality into two different functions.
- 40:58And now it's completely clear to the reader what was intended.
- 41:01And if later on you need to do some refactoring and you need to find all of the places where you created a hierarchical index, well, you just search for the function name.
- 41:11You don't have to search for the function and then probe the type of that argument to know whether or not you're getting a hierarchical index.
- 41:17Yeah, that's a tremendous difference.
- 41:19And, you know, you go to your fancy ID, you right click, you say find usages, it'll say there are six.
- 41:25They are here.
- 41:26Yeah, exactly.
- 41:28Exactly.
- 41:28That's way better than they're here, but only sometimes.
- 41:33Like that's a little sketchy for sure.
- 41:35That's right.
- 41:36All right.
- 41:36So it sounds like there's a lot of maybe familiarity if you're coming from Pandas, but there's enough difference that this is really something on its own and special.
- 41:46And there's good reasons to use it.
- 41:48One of the key things from Pandas is the, well, I mean, in Pandas, it took Pandas to figure this out too, is that there's three types of selection.
- 41:56When we're selecting data, there is the root get item selection, which in Pandas overwhelmingly is used for column selection, but in some rare cases can be used for row selection.
- 42:06That's something we changed, but I'll get back to that.
- 42:08So there's the get item, there's the .loc selection, which can take one argument for row selection, two arguments for row and column selection, and the iLock selection, which uses integers instead of the labels of the index.
- 42:21So that family of those three selectors really gives you everything you need.
- 42:26Now, Pandas at various times had other types of selectors.
- 42:30There's this IX method, and there's a few other variants, but they seem to be getting rid of those.
- 42:35Recognizing that there's these three types of selection really is one of the fundamental things to bridge the gap for people coming from Pandas to static frame.
- 42:45Those are relatively the same.
- 42:46One of the key differences we made in line with consistency and having only one way to do things is the root get item selection interface is only a column selector.
- 42:56It is never a row selector, which is a shortcut you can do in Pandas, but again, it's undesirable, is not clear for readability, and is difficult for refactoring.
- 43:06Yeah.
- 43:06Interesting.
- 43:08Okay, cool.
- 43:09There's three types of selections, the root get item, the lock, and the iLock, and then we expose them in sub-interfaces, if you will.
- 43:16So a relevant question is, if I have an immutable data frame, how do I do assignment?
- 43:21Well, you don't.
- 43:23But Pandas and also NumPy have these really powerful ways of doing an assignment.
- 43:29I can do an assignment with Pandas.
- 43:31I can do an assignment in a lock call, in an LLC.
- 43:36And I can assign to an entire column.
- 43:38I can assign to an entire row.
- 43:40I can assign to a mixture of columns and rows by using the same syntax I use for selection.
- 43:45That's an awesome feature.
- 43:46I wanted to maintain that same expressive interface, but you can't do in-place mutation.
- 43:54So how do you do it?
- 43:55Well, on static frame, there's a .assign attribute.
- 43:58And that .assign attribute exposes a root get item, a lock, and an iLock.
- 44:05So under that assign attribute, you can do all of the same type of assignment moves you
- 44:10used to do, only you get back a new frame, and you're not mutating the old frame in place.
- 44:15That's a great feature.
- 44:16I love it.
- 44:16So let's talk about testing for a little bit.
- 44:19I saw that you have unit tests for performance tests, unit tests, things like that, which is
- 44:25great.
- 44:25One of the things that really stood out to me when I was looking at it was that you actually
- 44:31were using hypothesis, which is an interesting library.
- 44:36I covered, I had Austin Bingham on the show long ago talking about hypothesis.
- 44:41It's probably been three years.
- 44:42But you want to just tell us roughly, really high level, what that is and why you decided
- 44:47to use it?
- 44:48I saw at last, I think it was last year's PyCon presentation on, maybe it wasn't specifically
- 44:53hypothesis, but it was related to that.
- 44:56Property-based testing in general.
- 44:57Yeah.
- 44:58And I just was so impressed.
- 44:59I was like, oh man, all that time I spend trying to find corner cases and trying to make my
- 45:05unit tests have sufficient coverage can be automated for me by using a tool that you control and you
- 45:14shape the random generation of values to meet the expectations of finding these extreme corner
- 45:20cases.
- 45:21I took that away and was like, wow, I really want to do more of that.
- 45:23One of my colleagues here at Research Affiliates who does some work in Haskell set off on trying
- 45:28to use this a little bit more in depth.
- 45:30And this whole idea of property testing, in fact, comes out of Haskell.
- 45:34I forget the name of the library that originated it, but the whole library was published as one
- 45:42page on the paper that introduced the concept.
- 45:44It's really amusing, but the implementation of the original sort of property-based testing tool
- 45:49is just one page of Haskell code.
- 45:52But through his example, my colleagues' examples and starting to look at it, I'm like, man, this is
- 45:57exactly what I need for static frame because, you know, you're trying to build a general purpose
- 46:01library.
- 46:01There's no way I'm going to be able to anticipate the things that people are going to want to put
- 46:05into a series or a frame.
- 46:07There's no idea that I can anticipate all the possible values someone is going to try to put
- 46:11in an index.
- 46:13So with property-based testing, with using hypothesis, you open the door to just defining
- 46:19the properties that you expect to have.
- 46:22You know, namely that if you create an index with 20 integers, the resultant index is going
- 46:29to have 20 values.
- 46:31Well, that's true unless you've duplicated any values.
- 46:33Or that's true if it's not true if you duplicated values.
- 46:37Or it's not true if something else went wrong in reading those values.
- 46:41So I think of hypothesis in the context of static frame as a way of simulating my user.
- 46:46It's, you know, the user.
- 46:48It's thousands of users who are throwing everything into these containers.
- 46:51And hypothesis really nicely gives you a way to model that and really changes the way you
- 46:57think about testing.
- 46:58Again, my same colleague, you know, was like, you know, I enjoy testing again.
- 47:02I enjoy writing tests so much more when using this because it just forces you to think about
- 47:08it in a different way.
- 47:09And it's very refreshing compared to the task of writing unit tests.
- 47:12Yeah, it's cool.
- 47:13It's almost like writing a meta test, right?
- 47:15Instead of going like, here are the seven cases.
- 47:17Here's one where the value's in the middle.
- 47:18Here's the edge of the array I'm trying to test.
- 47:20Here's one that's out of the bounds.
- 47:22You can just go, this is the general type of stuff that goes in.
- 47:26These are the general types of things I want to verify.
- 47:29Go make that happen and vary a bunch of stuff for me, right?
- 47:33Yeah, yeah, that's right.
- 47:34Yeah, it's pretty cool.
- 47:35So I was really thrilled to see that you had put that in there for some of the testing stuff.
- 47:39It's cool.
- 47:39People can check it out in the GitHub repo.
- 47:41Yeah, I have a lot more to do there.
- 47:42But again, it's like you have to go into it.
- 47:45What's really startling about it is you really have to be in a different mindset.
- 47:48So you have to give yourself the time to get into mindset.
- 47:51There's much more I need to do with that.
- 47:52But it's a refreshing and pleasurable place to be in.
- 47:57So yeah, I highly recommend it.
- 47:58Yeah, I bet.
- 47:59It seems super cool.
- 48:00It definitely seems like you can't just bring your main way of thinking about testing.
- 48:04Like, I'm going to test this one case and see if it works.
- 48:06You've got to sort of step back a level.
- 48:08Yeah, that's exactly right.
- 48:09Yeah, nice.
- 48:10Another thing I wanted to ask you about that I didn't before when we talked about Python
- 48:14and finance and just we're coming up on 2020.
- 48:18It's the death clock for Python 2 is ticking at pythonclock.org.
- 48:22I think it is.
- 48:23It's ticking down.
- 48:25The time is getting short on it.
- 48:27What is it like?
- 48:28Is first of all, the static frame support for Python 3?
- 48:31Oh, it built entirely in Python 3.
- 48:33We're at 3.5 now.
- 48:35No support for 2.
- 48:37So that was a huge benefit of my predecessor here.
- 48:40Research Affiliates.
- 48:41He set out building our code base in Python 3 back in 2012 or even 2011, which some people
- 48:47would have said, might have said was, you know, kind of questionable choice.
- 48:51But at that point, we had NumPy and we had Pandas soon after that.
- 48:55So given that foundation of Python 3, we've been using Python 3 entirely and have never looked
- 48:59back.
- 48:59Yeah, that's super.
- 49:00And then what do you see that transition looking like in the finance space larger?
- 49:07Not necessarily just for your firm, but the other folks you interact with as well.
- 49:11In terms of moving to Python 3?
- 49:13Yeah.
- 49:13Like, do people just have their head in the ground and go, we're just not doing it?
- 49:16Are they going like, oh my gosh, here it comes.
- 49:17This is going to be like Y2K again.
- 49:19Or do they, are they ambivalent?
- 49:21What's the finance vibe around that?
- 49:23I can't speak broadly.
- 49:24I do know that there's a very large bank that employs a very large number of Python developers
- 49:30who use a lot of extensive systems built entirely in Python 2.
- 49:35And I don't know if they're even on 2.7 or 2.5.
- 49:38Yeah, I think the bank that you were talking about, I think I know.
- 49:41And I don't even think they're on 2.7.
- 49:42Yeah, I think they're stuck on 2.5 is what I heard.
- 49:44But it's going to be very hard, I would expect.
- 49:47Maybe they've built their frameworks in such a way that maybe they're okay.
- 49:52One of the things I've heard about that very large bank is that their Python tools, to some extent,
- 49:58are enforcing immutability.
- 50:00And for the same motivations that we have, they may have put constraints on the language
- 50:05in a way to help reduce risk that they can keep for a little while.
- 50:09But certainly, it's going to require a transition at some time, and that's going to be hard.
- 50:13Yeah, I agree.
- 50:14I guess two thoughts.
- 50:15One, do you feel like maybe that is a failure of leadership, engineering leadership, to say,
- 50:23we put ourselves in a corner, you guys, and we have to.
- 50:26I know it's not building features or driving the investment engine, but we have to keep moving
- 50:32forward if we get stuck, not just on 2.7, but on 2.5.
- 50:36And all these libraries, they can't use anything NumPy is doing, or Pandas, or in the future,
- 50:41right, as they're dropping, right?
- 50:42You know, Pandas already announced they're dropping Python 2 support.
- 50:44Right, I saw that.
- 50:45Yeah, it's definitely a challenge.
- 50:47And it's technical debt, right?
- 50:48It's, as, you know, my own team, we're on 3.5, and we're in the process of jumping to 3.7.
- 50:55You know, even that, for us, as a relatively small team with a decent but modest-sized code base,
- 51:01you know, it takes work and it takes time.
- 51:03And just as you say, it doesn't deliver immediate features.
- 51:05It doesn't deliver obvious benefits.
- 51:07It is a technical debt.
- 51:08And it's often, it's very difficult to prioritize that work appropriately, and also to communicate
- 51:14the value to upper management and others that are considering what your developers are doing.
- 51:20But it's, I mean, the important thing is that it's called debt for a reason.
- 51:25You have to pay it, or your survivors will pay it.
- 51:28There is no debt forgiveness in technical debt, other than abandonment.
- 51:34I mean, you can abandon the code and start over.
- 51:37There's no too big to fail, sort of, really.
- 51:39Yeah, so it's definitely something to pay attention to.
- 51:43I mean, even with Pandas versions, we've struggled to keep up with Pandas updates.
- 51:48We're still presently using Pandas 17.
- 51:51We are transitioning to Pandas 23 or 24.
- 51:54I think we're going to 24 now.
- 51:55I think 25 just came out.
- 51:56But even before we were on 17, we suffered and spent quite a bit of time accommodating the changes to the API
- 52:04and changes downstream of Pandas changes.
- 52:08So it's painful, but you just have to do it.
- 52:11Yeah, in their defense, right?
- 52:13That's a lot of money.
- 52:14If you're rewriting the code significantly, that's touching money versus just driving the website or whatever.
- 52:20I can understand the hesitation.
- 52:22I want to mess with that.
- 52:23But at some point, maybe it's not in 2020.
- 52:26Maybe it's 2025.
- 52:27At some point, it's going to be a problem.
- 52:29People are going to go, I don't want to work there.
- 52:31You mean really?
- 52:32That version from that long ago with that few library support?
- 52:36No, thank you, right?
- 52:37Like, it's going to be a problem.
- 52:38It's going to be like cobalt.
- 52:39Yeah, yeah.
- 52:40Cobalt.
- 52:40I made a joke about cobalt the other day with some of my colleagues, and I was quickly corrected that there is –
- 52:47apparently there still is quite a bit of cobalt in production.
- 52:49Yes.
- 52:49So I was like – I thought it was like a dinosaur, but I guess there's still a lot of cobalt in production.
- 52:55But you can get away with it for so long.
- 52:57But at a certain point, yeah, you're exactly right.
- 53:00It's a huge detriment to recruiting.
- 53:03We're a small firm located in Newport Beach.
- 53:06Not exactly a tech hub, although Irvine's trying a little bit.
- 53:10But for as long as we've been recruiting for this team, I've been – less so now, but a few years ago, I would say to people, yeah, and we're working in Python 3.
- 53:18And they would say, oh, really?
- 53:19You're working in Python 3?
- 53:20I'm stuck in 2.7 or 2.5.
- 53:22I'm so excited.
- 53:23That would be awesome.
- 53:24I am so excited.
- 53:25So a few years ago, that we were entirely in Python 3 was explicitly a highly desirable feature for prospective candidates to our team.
- 53:36A little bit less so now, but it's something that we always say up front.
- 53:40Yeah.
- 53:40Well, it's definitely a good thing.
- 53:43I think only less so only because other people have started to make that path, go down that path, right?
- 53:50Yeah, that's right.
- 53:51I mean, when I was in – I went to a PyCon, I believe it was in 2013, and I believe it was at Guido's keynote.
- 53:59Maybe it was somebody else.
- 54:01But the question was asked to the general assembly, you know, when there's all thousands of – however many thousands of people are in that room.
- 54:07And they asked a show of hands of how many people are using Python 3 in production.
- 54:11And me and my colleague raise our hand and look around.
- 54:15And there's just – I mean, it was far less than 10%.
- 54:18Yeah.
- 54:18But I think they did that exercise again at a recent PyCon, and it was – looks like it was more than half, you know?
- 54:23Oh, yeah.
- 54:24Yeah.
- 54:24The community is definitely moving, and, you know, it's good to see.
- 54:27It's great to see.
- 54:28It's great to see.
- 54:29All right.
- 54:30Well, I think we're getting short on time, so we're going to have to leave it there.
- 54:34People should definitely check out Static Frame.
- 54:36If Pandas is something that you're doing, maybe this will apply.
- 54:40I guess maybe one final question I could ask for you, Chris, is how does somebody know that they have a problem that Static Frame will solve better than Pandas is solving?
- 54:48Yeah.
- 54:49I mean, often the advice will be like, hey, yeah, use Pandas, right?
- 54:52Load CSV, all that kind of stuff.
- 54:54But, like, when would you say, actually, you should consider this because it'll solve your problem better?
- 54:59I would say there's a couple signs.
- 55:00One might be that you keep on making mistakes.
- 55:04You make mistakes because you reach for the wrong interface, or you get a surprising result because there's a type sensitivity to an argument, or you make a mistake because you accidentally mutated data you didn't intend to mistake, or you got a multi-index when you expected a unique index.
- 55:21You know, those are the kinds of things that are the telltale signs that maybe the kind of work you're doing, you know, requires a different package with a different set of constraints.
- 55:30Yeah, that's right.
- 55:30That's a great description.
- 55:31Thanks.
- 55:32All right.
- 55:32Now, before you get out of here, I've got the final two questions.
- 55:34Sure.
- 55:35If you're going to write some Python code or work on Static Frame, what editor do you use?
- 55:38I am recently moved over to VS Code, as many people may have had some apprehension about Microsoft products for some time.
- 55:46And now there's a Microsoft product that I use every day and really enjoy.
- 55:50Prior to that, I used a few different editors, but I've been really happy with VS Code.
- 55:54In large part, I don't really ask a lot for my IDE.
- 55:57I really want it to get out of my way, and I don't debug in the IDE.
- 56:02I don't lint in the IDE.
- 56:04I prefer to do those things from the command line.
- 56:06I just like my ID to be something close to like a Zen mode that gets everything out of the way, and I'm very aesthetically inclined,
- 56:14so I'm very sensitive to my colors and whatnot.
- 56:16So with VS Code, I was able to quickly, with a very low transition cost, get it to be visually, aesthetically, sort of ergonomically comfortable for me.
- 56:27And in subsequent updates, it hasn't made it worse.
- 56:30It's been good.
- 56:31So I've been very happy with VS Code.
- 56:33That's cool.
- 56:33Yeah, they're doing great stuff with that, so I definitely hear that a lot.
- 56:36All right.
- 56:37And then notable PyPI package.
- 56:39I'll go ahead and throw a static frame out there for you.
- 56:41People can pip install that, right?
- 56:42Yep.
- 56:43Yep.
- 56:43It's there.
- 56:44Ready to go.
- 56:44All right.
- 56:44Other ones that you're like, oh, I heard about this the other day.
- 56:47Maybe you don't know about it, but it's really cool.
- 56:49It solves this problem uniquely or whatever.
- 56:51Any come to mind?
- 56:51I should plug the project I worked at before I started at Research Affiliates, which is Music21.
- 56:56Music21 is a Python package that I co-created and founded and did sort of initial three years of work on it at MIT with a former colleague of mine there,
- 57:06which is a really fun tool for the other day.
- 57:07Which is a really fun tool for examining what we call symbolic music.
- 57:11So music represented as XML or music represented as MIDI files.
- 57:15Music21 allows you to take in these musical representations and play with them as an object model and ask questions about them.
- 57:24Like, for example, given all of Mozart's string quartets, how often does he use a modified pitch on the third beat or something like that?
- 57:34Uh-huh.
- 57:34Awesome.
- 57:35So it's a really fun toolkit if you know anything about music and you want to start experimenting with generating or analyzing musical notation.
- 57:42Okay.
- 57:43That's a great recommendation.
- 57:44That's very cool.
- 57:44All right.
- 57:45Final call to action.
- 57:46People want to get started with static frame.
- 57:48What do they do?
- 57:48I did the essential thing recently.
- 57:50I made a quick start guide.
- 57:51So I started to write API documentation, and that was kind of tough.
- 57:57And it's not a pleasurable read and not a good introduction.
- 58:00So I fairly recently wrote a little quick start guide.
- 58:02You can find it on GitHub in the readme.
- 58:04You can find it in the documentation, which is a little tutorial using data available from a JSON endpoint that will walk you through some of the key features and main differences from Pandas.
- 58:14And hopefully will be enough to get people excited about the package.
- 58:18Yeah, very cool.
- 58:19And you also gave a presentation at PyCon, which was recorded.
- 58:21I'll link to that so people can check that out.
- 58:23Final question.
- 58:24Are you looking for open source contributors, people to jump on this project, or is it kind of baked?
- 58:29What's the status there?
- 58:30Oh, absolutely.
- 58:30So while this tool is being used internally within my firm and its use will grow within our firm, we are absolutely looking for contributors and users and testers to give us some feedback.
- 58:45I've been fortunate in the development of this in that I've had my team to constantly give me feedback and tell me I'm being too nice, as they like to do, to make our interfaces discreet and precise and get a lot of feedback and support from my team.
- 59:01So I owe a huge debt to my team and the context of our work here to support that.
- 59:05But we need more users.
- 59:06We need more testers.
- 59:07We need more feedback.
- 59:08So at a basic level, people using the tool and giving us some feedback, they may not be ready to move it into it into their production systems.
- 59:15And I certainly understand that.
- 59:16But some good dabbling, starting to play with it would be really helpful for us in getting some feedback.
- 59:21And of course, if I'm pretty happy with the code itself, I would encourage those to look at the code.
- 59:25They see opportunities to add things and make things better.
- 59:28That would be fantastic as well.
- 59:29Yeah, super.
- 59:29All right.
- 59:30Well, thanks for giving us the whole story and history of Static Frame.
- 59:34It looks like a really cool project.
- 59:35Great.
- 59:35Thank you for your time.
- 59:36Happy to be on the show.
- 59:37Yep.
- 59:37Happy to have you.
- 59:38Bye.
- 59:38Bye-bye.
- 59:38This has been another episode of Talk Python To Me.
- 59:42Our guest on this episode was Christopher Ariza, and it's been brought to you by Linode and Stellarress.
- 59:47Linode is your go-to hosting for whatever you're building with Python.
- 59:51Get four months free at talkpython.fm/Linode.
- 59:55That's L-I-N-O-D-E.
- 59:57Find the right job for you with Stellarress, the AI-powered talent agent for the top tech talent.
- 1:00:03Visit talkpython.fm/Stellarress to get started.
- 1:00:06That's talkpython.fm/S-T-E-L-L-A-R-E-S.
- 1:00:11Stellarress.
- 1:00:12Want to level up your Python?
- 1:00:14If you're just getting started, try my Python Jumpstart by Building 10 Apps course.
- 1:00:19Or if you're looking for something more advanced, check out our new Async course that digs into all the different types of Async programming you can do in Python.
- 1:00:27And of course, if you're interested in more than one of these, be sure to check out our Everything Bundle.
- 1:00:32It's like a subscription that never expires.
- 1:00:34Be sure to subscribe to the show.
- 1:00:36Open your favorite podcatcher and search for Python.
- 1:00:39We should be right at the top.
- 1:00:40You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
- 1:00:49This is your host, Michael Kennedy.
- 1:00:51Thanks so much for listening.
- 1:00:52I really appreciate it.
- 1:00:53Now get out there and write some Python code.
- 1:00:58I really appreciate it.