Git Product home page Git Product logo

Comments (4)

ariddell avatar ariddell commented on May 18, 2024

I find myself doing similar operations. @JanSchulz have you tried to express some of your functions in terms of functions available in toolz (toolz.dicttoolz) or funcy?

There's a lot of overlapping functionality between boltons, toolz, and funcy; I'm not sure which package to use for these kinds of operations. Perhaps others have advice?

from boltons.

mahmoud avatar mahmoud commented on May 18, 2024

Oh, yes, these very much fit in. In fact, I've got TODOs in iterutils and I'd already started on a couple experimental implementations in my ipython notebook, but still haven't found the right one yet. That said, my current get_path is almost identical to your get_from_structure except that it, in addition to the string, it also allows a tuple/list version of the path for more compatibility with remap (and general easier programmatic path construction). There's also handling for the corner case of numeric string keys in dictionaries. Otherwise, in other words, I very much approve! :)

@ariddell So I discovered toolz a long time ago, before boltons for sure, and I was quite excited. But while on the whole it has more operations in this domain, I found myself barely using any of them. toolz tries hard to provide a certain functional paradigm, and I didn't find the operations that much clearer than the standard ones.

In this specific case, I think remap is unique among both libraries, as it's for customizably working with arbitrarily nested data. Most toolz I've seen are (for others) handy conventions for dealing with one or two levels of nesting.

from boltons.

kurtbrose avatar kurtbrose commented on May 18, 2024

Totally agree, there is a whole family of functions available here, all slightly different.
It is hard to tell what the "complete" set of operations would be.

find_in_structure and get_from_structure is an example of operating with paths, which there are many ways to do. ("Path" meaning a sequence of attribute / item accesses which can be stored and applied to any object.) One implementation I've made works with future objects -- a path would be stored expressing what data to access on the future response.

I'm hoping there is some clean abstraction that covers many cases. Something like SQL for trees. There are systems like JSONiq and XQuery (http://www.jsoniq.org/) which make a good reference point. Their downsides are they require an external library and I think operating on "result sets" is the wrong abstraction.

There are some other examples out there too this is a fun research project for me for now :-) Maybe something will come of it.

from boltons.

jankatins avatar jankatins commented on May 18, 2024

@mahmoud the tuple-as-path variant was what draw me to this bugtracker :-) I've no problem to rebuilt my variant with that in mind, but I think that you already have them :-)

The convert_to_dataframe_input can probably redone in with a function which wraps remap, but IMO this results in more overhead (many more comparisons, as all possible paths in the structure have to be checked and not only some specific ones "tried". Reading you todo, I like the idea of "collecting" something in the structure, so collect(data, pathes) sounds fine, too.

I can submit this as a PR (as addition in iterutils) if that's easier to discuss.

from boltons.

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.