-
Notifications
You must be signed in to change notification settings - Fork 0
Introduce ChainableArray class and add mapping functions #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Hi Thomas, wow, lots of mappings, very cool! Looking through it, I think the ChainableArray + utils should live in their own module to keep the semantics of the mappings module clean 🤔 However, this could also be done later, since it is abstracted away from importers by the top-level init. Also, let's add those unit tests as soon as possible. |
|
I updated the maximum python version to be tested during the github workflow to 3.13, so we have 3.7 to 3.13 for now |
|
I followed sherlockhommel's suggestion and restructured pyamapping, moving ChainableArray to chainable_array.py. The idea is that mappings.py should be reserved for mapping functions. Registration of numpy ufuncs and pyamapping functions were moved to init.py. |
|
I spent just a little bit of time adding a few very basic tests for some mappings - planning to expand on those later. I noticed that the bilin mapping requires scipy to work, so I added scipy as a new dependency (in setup.cfg). |
|
I added basic tests for most mapping functions (few still missing, such as ecdf, interp, interp_spline...) |
so far scipy is only required for interp_spline (which, however is used by bilin()). So the question is whether we should have scipy as optional dependency to keep pyamapping lightweight, and issue a (scipy missing) warning in case bilin() or interp_spline() are used. Ideas? related issue: ChainableArray features to_asig() which imports pya.Asig and plot() which imports matplotlib: makes sense to have these as optional dependencies. Maybe we should use module import flags to avoid repeated import checks? |
|
I think for now it would work to have matplotlib, pya and scipy as optional dependencies and then do a dynamic import that checks whether the module has been imported before. Maybe something like this: but a little more refined to the specific scipy / matplotlib / pya submodule that is needed. |
Summary
Introduces a new ChainableArray class that provides a fluent, chainable interface for array transformations. This allows more expressive functional operations on arrays while maintaining readability. ChainableArray integrates both existing numpy ufuncs and custom mapping functions for chainable operations. The pyamapping-examples.ipyng Jupyter notebook provides extensive examples.
Motivation
amp_to_db(clip(linlin(myarray, x1, x2, y1, y2), c1, c2))leads to reverse reading order, argument fragmentation and parenthesis clutter. A chain-like syntax, as introduced with pya enhances readability. ChainableArray allows to rewrite the example above asmyarray.linlin(x1, x2, y1, y2).clip(c1, c2).amp_to_db().Changes
Testing
Review notes