You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/08/04 19:12:55 UTC

[GitHub] [beam] apilloud commented on a change in pull request #12459: [BEAM-9547] Simplify pandas implementation.

apilloud commented on a change in pull request #12459:
URL: https://github.com/apache/beam/pull/12459#discussion_r465257198



##########
File path: sdks/python/apache_beam/dataframe/frame_base.py
##########
@@ -147,7 +149,11 @@ def wrapper(*args, **kwargs):
       else:
         try:
           # pylint: disable=deprecated-method
-          ix = inspect.getargspec(func).args.index(key)
+          if sys.version_info < (3, ):

Review comment:
       nit: this appears more than once in this file, might it be worth adding a `getargspec` helper function?

##########
File path: sdks/python/apache_beam/dataframe/frame_base.py
##########
@@ -226,6 +232,68 @@ def wrapper(self, *args, **kwargs):
   return wrapper
 
 
+def maybe_inplace(func):
+  @functools.wraps(func)
+  def wrapper(self, inplace=False, **kwargs):
+    result = func(self, **kwargs)
+    if inplace:
+      self._expr = result._expr
+    else:
+      return result
+
+  return wrapper
+
+
+def args_to_kwargs(base_type):
+  def wrap(func):
+    if sys.version_info < (3, ):
+      getargspec = inspect.getargspec
+    else:
+      getargspec = inspect.getfullargspec
+
+    # This is used to map all positional arguments to keyword arguments.
+    base = getattr(base_type, func.__name__)
+    while hasattr(base, '__wrapped__'):
+      base = base.__wrapped__
+    base_argspec = getargspec(base)
+    arg_names = base_argspec.args
+
+    # These are used to populate any defaults in base for arguments in func.
+    if base_argspec.defaults:
+      arg_to_default = dict(
+          zip(
+              base_argspec.args[-len(base_argspec.defaults):],
+              base_argspec.defaults))
+    else:
+      arg_to_default = {}
+
+    unwrapped_func = func
+    while hasattr(unwrapped_func, '__wrapped__'):
+      unwrapped_func = unwrapped_func.__wrapped__
+    # args that do not have defaults in func, but do have defaults in base

Review comment:
       This comment is a little confusing, I believe it is describing the contents of `populate_defaults`?
   
   After spending some time reading through this, it might be clearer if you broke this into a function that returned `arg_to_default`, and a second that returned `populate_defaults`.

##########
File path: sdks/python/apache_beam/dataframe/frame_base.py
##########
@@ -226,6 +232,68 @@ def wrapper(self, *args, **kwargs):
   return wrapper
 
 
+def maybe_inplace(func):
+  @functools.wraps(func)
+  def wrapper(self, inplace=False, **kwargs):
+    result = func(self, **kwargs)
+    if inplace:
+      self._expr = result._expr
+    else:
+      return result
+
+  return wrapper
+
+
+def args_to_kwargs(base_type):

Review comment:
       This seems generic and useful enough that I'm surprised it isn't in a dataframes library.

##########
File path: sdks/python/apache_beam/dataframe/frame_base.py
##########
@@ -226,6 +232,68 @@ def wrapper(self, *args, **kwargs):
   return wrapper
 
 
+def maybe_inplace(func):
+  @functools.wraps(func)
+  def wrapper(self, inplace=False, **kwargs):
+    result = func(self, **kwargs)
+    if inplace:
+      self._expr = result._expr
+    else:
+      return result
+
+  return wrapper
+
+
+def args_to_kwargs(base_type):
+  def wrap(func):
+    if sys.version_info < (3, ):
+      getargspec = inspect.getargspec
+    else:
+      getargspec = inspect.getfullargspec
+
+    # This is used to map all positional arguments to keyword arguments.
+    base = getattr(base_type, func.__name__)
+    while hasattr(base, '__wrapped__'):
+      base = base.__wrapped__
+    base_argspec = getargspec(base)
+    arg_names = base_argspec.args
+
+    # These are used to populate any defaults in base for arguments in func.
+    if base_argspec.defaults:
+      arg_to_default = dict(

Review comment:
       `arg_to_default` might be clearer as `arg_to_base_default` or `base_defaults`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org