GithubHelp home page GithubHelp logo

Add Series.drop_nil about explorer HOT 8 OPEN

josevalim avatar josevalim commented on July 18, 2024
Add Series.drop_nil

from explorer.

Comments (8)

cigrainger avatar cigrainger commented on July 18, 2024

Do we need the regular version of this? It feels like clutter. The idea of minimal verbs is that you can do everything you need with them. Why not just Series.filter(not is_nil(_))?

from explorer.

cigrainger avatar cigrainger commented on July 18, 2024

Just thinking out loud here: I think there's got to be a more elegant way of dealing with lists than cleaving to Polars's API too closely. I'm not sure I like everything about purrr but I wonder if something like map_depth might help us out here?

There's also modify_tree. Something that indicates it's recursive might be useful?

from explorer.

josevalim avatar josevalim commented on July 18, 2024

@cigrainger you are right, we don't need drop_nil at the root. However, the issue presented here is also available for many of the aggregate functions. How to distinguish between max of a list and maxof the series?

map_depth/modify_tree is definitely interesting. Implementing it is a bit less trivial. We would need to introduce some sort of LazyDepthSeries, that collects operations in a series, but as it relates to a struct or list field, and then translate that to polars. Do we want to go down this route?

from explorer.

cigrainger avatar cigrainger commented on July 18, 2024

Maybe. I need to explore how Polars handles this itself and in py polars.

from explorer.

cigrainger avatar cigrainger commented on July 18, 2024

So putting this a bit to the test with Python Polars:

It seems like nested lists may not be supported? That would fix the recursion problem pretty cleanly.

In [16]: df = pl.DataFrame({"values": [[None, 1, None, 2], [None], [3, 4], [[None, 1], [2], [None]]]})

In [17]: df
Out[17]:
shape: (4, 1)
┌────────────────────┐
│ values             │
│ ---                │
│ list[i64]          │
╞════════════════════╡
│ [null, 1, … 2]     │
│ [null]             │
│ [3, 4]             │
│ [null, null, null] │
└────────────────────┘

from explorer.

josevalim avatar josevalim commented on July 18, 2024

@cigrainger all lists need to be nested equally. When it fails to cast to a certain type, it returns null instead of raising.

from explorer.

billylanchantin avatar billylanchantin commented on July 18, 2024

@cigrainger Also, in case you missed it, there was an interesting saga of us discovering what Polars was doing WRT nested lists here:

Some take-aways:

  • The first element of a nested list is the tie-breaker when the dtype is ambiguous.
  • We decided to be more strict with our inference code than py-polars in certain situations.

from explorer.

cigrainger avatar cigrainger commented on July 18, 2024

I did! Thanks @billylanchantin

from explorer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.