Comments (4)
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.
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.
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.
@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)
- Function to format a list with commas and a final 'and'/'or'
- attrs/dataclasses-style decorator helper
- Mfnvhudhvsdmbc HOT 1
- Test failure with Python 3.11 HOT 1
- Tag for the 23.0.0 release is missing HOT 1
- Include tests in future pypi sdist tarball HOT 5
- Convert list of dict items to list of string items
- `ParsedException.from_string(text).to_string() == text` property violated due to anchors
- `boltons.ecoutils` `23.0.0` breaks `pdb` interactive prompt in `pytest` debug sessions HOT 4
- Non-empty `dictutils.OMD` cannot be loaded from `pickle` HOT 1
- RFC: Make boltons Python 3.7+ only. HOT 8
- Support in-place union for `dictutils.OrderedMultiDict` HOT 1
- [Feature request] Parametrize the delimiter to make glom use any kind of Path delimiter, not just `.` HOT 1
- wraps loses keywords
- chunked filter HOT 3
- tracking some ideas HOT 3
- LRU .values() and dict return old entries HOT 3
- call _orig_default identity
- Names in `boltons.strutils.__all__` with no definitions
- Missing git tags for 23.1.0 & 23.1.1 releases HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from boltons.