issues: 187373423
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
187373423 | MDU6SXNzdWUxODczNzM0MjM= | 1080 | acccessor extending approach limits functional programming approach, make direct monkey-patching also possible | 941907 | closed | 0 | 9 | 2016-11-04T16:06:34Z | 2016-12-06T10:44:16Z | 2016-12-06T10:44:16Z | NONE | Hi, thatnks for creating and continuing development of xarray. I'm in the process of converting my own functions and classes to it which did something very similar (label indexing, plotting, etc.) but was inferior in many ways. Right now I'm designing a set of functions for digital signal processing (I need them the most, though inteprolation is also important), mostly lowpass/highpass filters and spectrograms based on I agree that making sure that adding a method to the class does not overwrite something else is a good idea, but that can be done for single methods as well. It would be even possible to save replaced method somewhere and replace them later if requested. The great advantage is that the added methods can still be first-class functions as well. Such methods cannot save state as easily as accessor methods, but in many cases that is not necessary. I actually implemented something similar for my DataArray-like class (before xarray existed, now I'm trying to convert to ```python '''Module for handling various DataArray method plugins''' from xarray import DataArray from types import FunctionType map: name of patched method -> stack of previous methods_REPLACED_METHODS = {} def patch_dataarray(method_func): '''Sets method_func as a method of the DataArray class
def restore_method(method_func): '''Restore a previous version of a method of the DataArray class''' method_name = method_func.name try: method_stack = _REPLACED_METHODS[method_name] except KeyError: return # no previous method to restore previous_method = method_stack.pop(-1) if previous_method is None: delattr(DataArray, method_name) else: setattr(DataArray, method_name, previous_method) def unload_module_patches(module): '''Restore previous versions of methods found in the given module''' for name in dir(module): obj = getattr(module, name) if isinstance(obj, FunctionType): restore_method(obj) def patch_dataarray_wraps(func, func_name=None): '''Return a decorator that patches DataArray with the decorated function
``` |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/1080/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |