vendredi 11 février 2022

Design pattern - Python function applied to different objects

I have modified Numpy's apply_along_axis() function and I want to be able to use this function on different objects (such as xarray.DataArray and other multi-dimensional data structures). My modified apply_along_axis() coerces the input to a numpy array using np.asanyarray(). I would like to have a design pattern where i can apply this function to different objects but preserve the meta-data associated with those objects. The meta-data/attributes are now lost because of the coercion to a numpy array.

I do not want to modify the core functionality of apply_along_axis() or do type checking on the arguments within apply_along_axis(). I want to be able to easily add support for new data structures in the future... I was thinking of either wrapping the input datastructures or the apply_along_axis() function. But I'm not sure how to go about it. Looking for elegant solutions.

Aucun commentaire:

Enregistrer un commentaire