11 comments

  • rich_sasha6 hours ago
    The article starts well, on trying to condense pandas&#x27; gaziliion of inconsistent and continuously-deprecated functions with tens of keyword arguments into a small, condensed set of composable operations - but it lost me then.<p>The more interesting nugget for me is about this project they mention: <a href="https:&#x2F;&#x2F;modin.readthedocs.io&#x2F;en&#x2F;latest&#x2F;index.html" rel="nofollow">https:&#x2F;&#x2F;modin.readthedocs.io&#x2F;en&#x2F;latest&#x2F;index.html</a> called Modin, which apparently went to the effort of analysing common pandas uses and compressed the API into a mere handful of operations. Which sounds great!<p>Sadly for me the purpose seems to have been rather to then recreate the full pandas API, only running much faster, backed by things like Ray and Dask. So it&#x27;s the same API, just much faster.<p>To me it&#x27;s a shame. Pandas is clearly quite ergonomic for various exploratory interactive analyses, but the API is, imo, awful. The speed is usually not a concern for me - slow operations often seem to be avoidable, and my data tends to fit in (a lot of) RAM.<p>I can&#x27;t see that their more condensed API is public facing and usable.
    • sweezyjeezy2 hours ago
      The pandas API is awful, but it&#x27;s kind of interesting why. It was started as a financial time series manipulation library (&#x27;panels&#x27;) in a hedge fund and a lot of the quirks come from that. For example the unique obsession with the &#x27;index&#x27; - functions seemingly randomly returning dataframes with column data as the index, or having to write index=False every single time you write to disk, or it appending the index to the Series numpy data leading to incredibly confusing bugs. That comes from the assumption that there is almost always a meaningful index (timestamps).
    • bbkane3 hours ago
      Check out polars- I find it much more intuitive than pandas as it looks closer to SQL (and I learned SQL first). Maybe you&#x27;ll feel the same way!
      • rich_sasha1 hour ago
        I&#x27;ve looked at Polars. My sense is that Pandas is an interactive data analysis library poorly suited to production uses, and Polars is the other way around. Seemed quite verbose for example. Sometimes doing `series[&quot;2026&quot;]` is exactly the right thing to type.
      • Lyngbakr2 hours ago
        Agreed — I much prefer polars, too. IIRC the latest major version of pandas even introduced some polars-style syntax.
        • Patient01 hour ago
          which makes sense because I believe that polars was written by the same guy that did pandas (hence the name - panda and polar are bears)
  • few6 hours ago
    I felt like one or two decades ago, all the rage was about rewriting programs into just two primitives: map and reduce.<p>For example filter can be expressed as:<p><pre><code> is_even = lambda x: x % 2 == 0 mapped = map(lambda x: [x] if is_even(x) else [], data) filtered = reduce(lambda x, y: x + y, mapped, []) </code></pre> But then the world moved on from it because it was too rigid
    • mrlongroots2 hours ago
      MapReduce is nice but it doesn&#x27;t, by itself, help you reason about pushdowns for one. Parquet, for example, can pushdown select&#x2F;project&#x2F;filter, and that&#x27;s lost if you have MapReduce. And a reduce is just a shuffle + map, not very different from a distributed join. MapReduce as an escape hatch over what is fundamentally still relational algebra may be a good intuition.
    • mememememememo5 hours ago
      Performance aside it seems you could do most maybe a the ops with those three. I say three because your sneaky plus is a union operation. So map, reduce and union.<p>But you are also allowing arbitrary code expressions. So it is less lego-like.
    • bjourne1 hour ago
      Reductions are painful because they specify a sequence of ordered operations. Runtime is O(N), where N is the sequence length, regardless of amount of hardware. So you want to work at a higher level where you can exploit commutativity and independence of some (or even most) operations.
  • pavodive3 hours ago
    When I started reading about pandas complexity and the smaller set of operations needed, couldn&#x27;t help but think of R&#x27;s data.table simplicity.<p>Granted, it&#x27;s got more than 15 functions, but its simplicity seems to me very similar to what the author presented in the end.
    • Lyngbakr1 hour ago
      Back when I used to use Stackoverflow, someone would always come along with a data.table solution when I asked a question about dplyr. The terse syntax seemed so foreign compared to the obvious verb syntax of dplyr. But then I learned data.table and I&#x27;ve never looked back. It&#x27;s a superb tool!
  • kiviuq24 minutes ago
    there is also ZIO Prelude and ZIO schema...
  • hermitcrab2 hours ago
    &gt;a dataframe is a tuple (A, R, C, D): an array of data A, row labels R, column labels C, and a vector of column domains D.<p>What is &#x27;a vector of column domains D&#x27;? A description of how the data A maps to columns?
    • throw_await1 hour ago
      I think &quot;domain&quot; here is like the datatype
  • getnormality4 hours ago
    Hmm. Folks trying to discover the elegant core of data frame manipulation by studying... <i>pandas</i> usage patterns. When R&#x27;s dplyr solved this over a decade ago, mostly by respecting SQL and following its lead.<p>The pandas API feels like someone desperately needed a wheel and had never heard of a wheel, so they made a heptagon, and now millions of people are riding on heptagon wheels. Because it&#x27;s locked in now, everyone uses heptagon wheels, what can you do? And now a category theorist comes along, studies the heptagon, and says hey look, you could get by on a hexagon. Maybe even a square or a triangle. That would be simpler!<p>No. Stop. Data frames are not fundamentally different from database tables [1]. There&#x27;s no reason to invent a completely new API for them. You&#x27;ll get within 10% of optimal just by porting SQL to your language. Which dplyr does, and then closes most of the remaining optimality gap by going beyond SQL&#x27;s limitations.<p>You found a small core of operations that generates everything? Great. Also, did you know Brainfuck is Turing-complete? Nobody cares. Not all &quot;complete&quot; systems are created equal. A great DSL is not just about getting down to a small number of operations. It&#x27;s about getting down to <i>meaningful</i> operations that are <i>grammatically</i> composable. The relational algebra that inspired SQL already nailed this. Build on SQL. Don&#x27;t make up your own thing.<p>Like, what is &quot;drop duplicates&quot;? What are duplicates? Why would anyone need to drop them? That&#x27;s a pandas-brained operation. You want the <i>distinct</i> keys defined by a select set of key columns, like SQL and dplyr provide.<p>Who needs a separate select and rename? Select is already using names, so why not do your name management there? One flexible select function can do it all. Again, like both SQL and dplyr.<p>Who needs a separate difference operation? There&#x27;s already a type of join, the anti-join, that gets that done more concisely and flexibly, and without adding a new primitive, just a variation on the concept of a join. Again, like both SQL and dplyr.<p>Props to pandas for helping so many people who have no choice but to do tabular data analysis in Python, but the pandas API is not the right foundation for anything, not even a better version of pandas.<p>[1] No, row labels and transposition are not a good enough reason to regard them as different. They are both just structures that support pivoting, which is vastly more useful, and again, implemented by both R and many popular dialects of SQL.
    • DangitBobby3 hours ago
      I guess I have pandas brain because I definitely want to drop duplicates, 100% of the time I&#x27;m worried about duplicates and 99% of the time the only thing I want to do with duplicates is drop them. When you&#x27;ve got 19 columns it&#x27;s _really fucking annoying_ if the tool you&#x27;re using doesn&#x27;t have an obvious way to say `select distinct on (<i>) </i> from my_shit`. Close second at say, 98% of the time, I want to a get a count of duplicates as a sanity check because I know to expect a certain amount of them. Pandas makes that easy too in a way SQL makes really fucking annoying. There are a lot of parts on pandas that made me stop using it long ago but first class duplicates handling is not among them.<p>And the API is vastly superior to SQL is some respects from a user perspective despite being all over the place in others. Dataframe select&#x2F;filtering e.g. df = df[df.duplicated(keep=&#x27;last&#x27;)] is simple, expressive, obvious, and doesn&#x27;t result in bleeding fingers. The main problem is the rest of the language around it with all the indentations, newlines, loops, functions and so on can be too terse or too dense and much hard to read than SQL.
      • getnormality3 hours ago
        Duplicates in source data are almost always a sign of bad data modeling, or of analysts and engineers disregarding a good data model. But I agree that this ubiquitous antipattern that nobody should be doing can still be usefully made concise. There should be a select distinct * operation.<p>And FWIW I personally hate writing raw SQL. But the problem with the API is not the data operations available, it&#x27;s the syntax and lack of composability. It&#x27;s English rather than ALGOL&#x2F;C-style. Variables and functions, to the extent they exist at all, are second-class, making abstraction high-friction.
        • doug_durham37 minutes ago
          Duplicates are a sign of reality. Only where you have the resources to have dedicated people clean and organize data do you have well modeled data. Pandas is a power tool for making sense of real data.
        • DangitBobby3 hours ago
          Oooh buddy how&#x27;s the view from that ivory tower??<p>But seriously I&#x27;m not in always in control of upstream data, I get stuff thrown over to my side of the fence by an organization who just needs data jiggled around for one-off ops purposes. They are communicating to me via CSV file scraped from Excel files in their Shared Drive, kind of thing.
          • getnormality2 hours ago
            Do what you gotta do, but most of my job for the past decade has been replacing data pipelines that randomly duplicate data with pipelines that solve duplication at the source, and my users strongly prefer it.<p>Of course, a lot of one-off data analysis has no rules but get a quick answer that no one will complain about!
            • DangitBobby2 hours ago
              I updated my OG comment for context. As an org we also help clients come up with pipelines but it&#x27;s just unrealistic to do a top-down rebuild of their operations to make one-off data exports appeal to my sensibilities.
              • getnormality2 hours ago
                I agree, sometimes data comes to you in a state that is beyond the point where rigor is helpful. And for some people that kind of data is most of their job!
        • mamcx1 hour ago
          &gt; Duplicates in source data are almost always a sign of bad data modeling<p>Nope. Duplicates in source data(INPUT) is natural, correct and MUST be supported or almost all data become <i>impossible</i>.<p>What is the <i>actual</i> problem is the OUTPUT. Duplicates on the OUTPUT need to be controlled and explicit. In general, we need in the OUTPUT a unique <i>row</i>by a N-key, but probably not need it to be unique for the rest, so, in the relational model, you need unique for a combination of columns (rarely, by ALL of them).
      • gregw23 hours ago
        You articulate your case well, thank you!<p>I always warn people (particularly junior people) though that blindly dropping duplicates is a dangerous habit because it helps you and others in your organization ignore the causes of bad data quickly without getting them fixed at the source. Over time, that breeds a lot of complexity and inefficiency. And it can easily mask flaws in one&#x27;s own logic or understanding of the data and its properties.
        • DangitBobby3 hours ago
          When I&#x27;m in pandas (or was, I don&#x27;t use it anymore) I&#x27;m always downstream of some weird data process that ultimately exported to a CSV from a team that I know has very lax standards for data wrangling, or it is just not their core competency. I agree that duplicates are a smell but they happen often in the use-cases that I&#x27;m specifically reaching to pandas for.
    • doug_durham35 minutes ago
      SQL only works on well defined data sets that obey relational calculus rules. Pandas is a power tool for dealing with data as you find it. Without Pandas you are stuck with tools like Excel.
    • getnormality2 hours ago
      On reflection I think it&#x27;s possible I may have missed the potential positive value of the post a bit. Maybe analyzing pandas gets you down to a set of data frame primitives that is helpful to build any API. Maybe the API you start with doesn&#x27;t matter. I don&#x27;t know. When somebody works hard to make something original, you should try to see the value in it, even if the approach is not one you would expect to be helpful.<p>I stand by my warnings against using pandas as a foundation for thinking about tabular data manipulation APIs, but maybe the work has value regardless.
    • fn-mote4 hours ago
      Amen.<p>The author takes the 4 operations below and discusses some 3-operation thing from category theory. Not worth it, and not as clear as dplyr.<p>&gt; But I kept looking at the relational operators in that table (PROJECTION, RENAME, GROUPBY, JOIN) and thinking: these feel related. They all change the schema of the dataframe. Is there a deeper relationship?
  • jiehong5 hours ago
    Dups of a few days ago:<p>- <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=47567087">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=47567087</a>
  • jeremyscanvic3 hours ago
    It&#x27;s very insightful how they explain the difference between dataframes and SQL tables &#x2F; standard relational structures!
  • Whyachi20 minutes ago
    [dead]
  • kokhanserhii2 hours ago
    [dead]
  • hermitcrab2 hours ago
    I guess this article is an interesting exercise from a pure maths point of view. But, as someone developing a drag and drop data wrangling tool the important thing is creating a set of composable operations&#x2F;primitive that are meaningful and useful to your end user. We have ended up 73 distinct transforms in Easy Data Transform. Sure they overlap to an extent, but feel they are at the right semantic level for our users, who are not category theorists.
    • tikhonj48 minutes ago
      You can have both: you start with a small, mathematically inspired algebraic core, then you express the higher-level more user-friendly operations <i>in terms</i> of the algebraic core.<p>As long as your core primitives are well designed (easier said than done!), this accomplishes two things: it makes your implementation simpler, and it helps guide and constrain your user-facing design. This latter aspect is a bit unintuitive (why would you want <i>more</i> constraints to work around?), but I&#x27;ve seen it lead to much better interface designs in multiple projects. By forcing yourself to express user-level affordances in terms of a small conceptual core, you end up with a user design that is more internally consistent and composable.
      • jimbokun31 minutes ago
        For one thing it gives users of your library fewer concepts to learn.
        • hermitcrab3 minutes ago
          Yes, but fewer concepts may not be simpler in practice. E.g. assembler is simpler than C++, but I wouldn&#x27;t want to write a big program in assembler.
    • mrlongroots2 hours ago
      Algebras are also nice for implementations. If you can decompose a domain into a few algebraic primitives you can write nice SIMD&#x2F;CUDA kernels for those primitives.<p>To your point, I wonder if the 73 distinct transforms were just different defaults&#x2F;usability wrappers over these. And you may also get into situations where kernels can be fused together or other batching constraints enable optimizations that nice algebraic primitives don&#x27;t capture. But that&#x27;s just systems---theory is useful in helping rethink API bloats and keeping us all honest.
      • hermitcrab1 hour ago
        They are effectively highly level wrappers over the most primitive operations. High enough level that they can be used from a GUI, rather than code.<p>It is a balance. Too few transforms and they become to low level for my users. Too many and you struggle to find the transform you want.
        • jimbokun29 minutes ago
          You don’t have to limit the transforms you offer users to just the core ones. But for your own sanity you can implement the none core ones in terms of the core ones.
    • whattheheckheck1 hour ago
      Have you heard of the book Mathematics for Big data<p><a href="https:&#x2F;&#x2F;github.com&#x2F;Accla&#x2F;d4m" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Accla&#x2F;d4m</a><p>He says himself the ideas are more important than the software package
      • hermitcrab1 hour ago
        D4M seems to be a library, not a book. Or am I missing something?