From 62231b6c558b38017b804b286304446469d50917 Mon Sep 17 00:00:00 2001 From: Kyle Prestel Date: Sat, 20 Oct 2018 11:40:19 -0400 Subject: [PATCH 1/7] CLN:Remove unused **kwargs from user facing methods Addresses GH18748 for user facing methods --- pandas/core/groupby/groupby.py | 14 ++++++++++++-- pandas/io/pytables.py | 17 ++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index ea7507799fa9a..473755cb115cf 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1755,7 +1755,12 @@ def cummin(self, axis=0, **kwargs): if axis != 0: return self.apply(lambda x: np.minimum.accumulate(x, axis)) - return self._cython_transform('cummin', numeric_only=False) + if kwargs: + numeric_only = kwargs.get('numeric_only') + else: + numeric_only = False + + return self._cython_transform('cummin', numeric_only=numeric_only) @Substitution(name='groupby') @Appender(_doc_template) @@ -1764,7 +1769,12 @@ def cummax(self, axis=0, **kwargs): if axis != 0: return self.apply(lambda x: np.maximum.accumulate(x, axis)) - return self._cython_transform('cummax', numeric_only=False) + if kwargs: + numeric_only = kwargs.get('numeric_only') + else: + numeric_only = False + + return self._cython_transform('cummax', numeric_only=numeric_only) def _get_cythonized_result(self, how, grouper, aggregate=False, cython_dtype=None, needs_values=False, diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 41e14e482d061..5efa8f17fc0ef 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -706,6 +706,9 @@ def select(self, key, where=None, start=None, stop=None, columns=None, auto_close : boolean, should automatically close the store when finished, default is False + kwargs + Additional keyword arguments passed to Storer + Returns ------- The selected object @@ -717,7 +720,7 @@ def select(self, key, where=None, start=None, stop=None, columns=None, # create the storer and axes where = _ensure_term(where, scope_level=1) - s = self._create_storer(group) + s = self._create_storer(group, **kwargs) s.infer_axes() # function to call on iteration @@ -1674,7 +1677,7 @@ def cvalues(self): def __iter__(self): return iter(self.values) - def maybe_set_size(self, min_itemsize=None, **kwargs): + def maybe_set_size(self, min_itemsize=None): """ maybe set a string col itemsize: min_itemsize can be an integer or a dict with this columns name with an integer size """ @@ -1687,13 +1690,13 @@ def maybe_set_size(self, min_itemsize=None, **kwargs): self.typ = _tables( ).StringCol(itemsize=min_itemsize, pos=self.pos) - def validate(self, handler, append, **kwargs): + def validate(self, handler, append): self.validate_names() def validate_names(self): pass - def validate_and_set(self, handler, append, **kwargs): + def validate_and_set(self, handler, append): self.set_table(handler.table) self.validate_col() self.validate_attr(append) @@ -3451,7 +3454,7 @@ def validate_data_columns(self, data_columns, min_itemsize): return [c for c in data_columns if c in axis_labels] def create_axes(self, axes, obj, validate=True, nan_rep=None, - data_columns=None, min_itemsize=None, **kwargs): + data_columns=None, min_itemsize=None): """ create and return the axes leagcy tables create an indexable column, indexable index, non-indexable fields @@ -3772,7 +3775,7 @@ def read_coordinates(self, where=None, start=None, stop=None, **kwargs): return Index(coords) - def read_column(self, column, where=None, start=None, stop=None, **kwargs): + def read_column(self, column, where=None, start=None, stop=None): """return a single column from the table, generally only indexables are interesting """ @@ -4727,7 +4730,7 @@ class Selection(object): """ - def __init__(self, table, where=None, start=None, stop=None, **kwargs): + def __init__(self, table, where=None, start=None, stop=None): self.table = table self.where = where self.start = start From 685ca22e4c1f751eecf9b5f2b9e65a69db1a449b Mon Sep 17 00:00:00 2001 From: Kyle Prestel Date: Sat, 20 Oct 2018 13:19:14 -0400 Subject: [PATCH 2/7] Fix CI build --- pandas/io/pytables.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 5efa8f17fc0ef..af0dd9fb120b7 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -3967,15 +3967,14 @@ class AppendableTable(LegacyTable): def write(self, obj, axes=None, append=False, complib=None, complevel=None, fletcher32=None, min_itemsize=None, - chunksize=None, expectedrows=None, dropna=False, **kwargs): + chunksize=None, expectedrows=None, dropna=False): if not append and self.is_exists: self._handle.remove_node(self.group, 'table') # create the axes self.create_axes(axes=axes, obj=obj, validate=append, - min_itemsize=min_itemsize, - **kwargs) + min_itemsize=min_itemsize) for a in self.axes: a.validate(self, append) From 23adda8caf0d623ef9b0c900489a0a1ea1f3949d Mon Sep 17 00:00:00 2001 From: Kyle Prestel Date: Sat, 20 Oct 2018 14:50:48 -0400 Subject: [PATCH 3/7] Fix CI build --- pandas/io/pytables.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index af0dd9fb120b7..597590145babb 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -688,7 +688,7 @@ def get(self, key): return self._read_group(group) def select(self, key, where=None, start=None, stop=None, columns=None, - iterator=False, chunksize=None, auto_close=False, **kwargs): + iterator=False, chunksize=None, auto_close=False): """ Retrieve pandas object stored in file, optionally based on where criteria @@ -706,9 +706,6 @@ def select(self, key, where=None, start=None, stop=None, columns=None, auto_close : boolean, should automatically close the store when finished, default is False - kwargs - Additional keyword arguments passed to Storer - Returns ------- The selected object @@ -720,7 +717,7 @@ def select(self, key, where=None, start=None, stop=None, columns=None, # create the storer and axes where = _ensure_term(where, scope_level=1) - s = self._create_storer(group, **kwargs) + s = self._create_storer(group) s.infer_axes() # function to call on iteration From 29a54bc2fec10ad263e72200707df405d3c25c91 Mon Sep 17 00:00:00 2001 From: Kyle Prestel Date: Sat, 20 Oct 2018 15:26:28 -0400 Subject: [PATCH 4/7] More CI fixes --- pandas/io/pytables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 597590145babb..3b22e308912a0 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -1404,7 +1404,7 @@ def _write_to_group(self, key, value, format, index=True, append=False, ) # write the object - s.write(obj=value, append=append, complib=complib, **kwargs) + s.write(obj=value, append=append, complib=complib) if s.is_table and index: s.create_index(columns=index) From 62e0dde2634b2ac0a366e139a5ff4fdc2153111b Mon Sep 17 00:00:00 2001 From: Kyle Prestel Date: Sun, 28 Oct 2018 12:26:44 -0400 Subject: [PATCH 5/7] Add kwargs back to support error handling --- pandas/core/groupby/groupby.py | 2 +- pandas/io/pytables.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 473755cb115cf..688f64e695c0a 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1755,7 +1755,7 @@ def cummin(self, axis=0, **kwargs): if axis != 0: return self.apply(lambda x: np.minimum.accumulate(x, axis)) - if kwargs: + if kwargs.get('numeric_only') or False: numeric_only = kwargs.get('numeric_only') else: numeric_only = False diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 3b22e308912a0..7e673c0366582 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -688,7 +688,7 @@ def get(self, key): return self._read_group(group) def select(self, key, where=None, start=None, stop=None, columns=None, - iterator=False, chunksize=None, auto_close=False): + iterator=False, chunksize=None, auto_close=False, **kwargs): """ Retrieve pandas object stored in file, optionally based on where criteria @@ -1404,7 +1404,7 @@ def _write_to_group(self, key, value, format, index=True, append=False, ) # write the object - s.write(obj=value, append=append, complib=complib) + s.write(obj=value, append=append, complib=complib, **kwargs) if s.is_table and index: s.create_index(columns=index) @@ -3451,7 +3451,7 @@ def validate_data_columns(self, data_columns, min_itemsize): return [c for c in data_columns if c in axis_labels] def create_axes(self, axes, obj, validate=True, nan_rep=None, - data_columns=None, min_itemsize=None): + data_columns=None, min_itemsize=None, **kwargs): """ create and return the axes leagcy tables create an indexable column, indexable index, non-indexable fields @@ -3964,14 +3964,14 @@ class AppendableTable(LegacyTable): def write(self, obj, axes=None, append=False, complib=None, complevel=None, fletcher32=None, min_itemsize=None, - chunksize=None, expectedrows=None, dropna=False): + chunksize=None, expectedrows=None, dropna=False, **kwargs): if not append and self.is_exists: self._handle.remove_node(self.group, 'table') # create the axes self.create_axes(axes=axes, obj=obj, validate=append, - min_itemsize=min_itemsize) + min_itemsize=min_itemsize, **kwargs) for a in self.axes: a.validate(self, append) From 61dcee3aa513f047b16f244b4984750994e12205 Mon Sep 17 00:00:00 2001 From: Kyle Prestel Date: Sat, 3 Nov 2018 12:14:36 -0400 Subject: [PATCH 6/7] Address merge comments --- pandas/core/groupby/groupby.py | 16 ++++------------ pandas/io/pytables.py | 3 ++- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 688f64e695c0a..0edba6f6b4f7f 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1755,12 +1755,8 @@ def cummin(self, axis=0, **kwargs): if axis != 0: return self.apply(lambda x: np.minimum.accumulate(x, axis)) - if kwargs.get('numeric_only') or False: - numeric_only = kwargs.get('numeric_only') - else: - numeric_only = False - - return self._cython_transform('cummin', numeric_only=numeric_only) + return self._cython_transform('cummin', + numeric_only=kwargs.get('numeric_only') or False) @Substitution(name='groupby') @Appender(_doc_template) @@ -1769,12 +1765,8 @@ def cummax(self, axis=0, **kwargs): if axis != 0: return self.apply(lambda x: np.maximum.accumulate(x, axis)) - if kwargs: - numeric_only = kwargs.get('numeric_only') - else: - numeric_only = False - - return self._cython_transform('cummax', numeric_only=numeric_only) + return self._cython_transform('cummax', + numeric_only=kwargs.get('numeric_only') or False) def _get_cythonized_result(self, how, grouper, aggregate=False, cython_dtype=None, needs_values=False, diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 7e673c0366582..4c28e0f88b1ae 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -3971,7 +3971,8 @@ def write(self, obj, axes=None, append=False, complib=None, # create the axes self.create_axes(axes=axes, obj=obj, validate=append, - min_itemsize=min_itemsize, **kwargs) + min_itemsize=min_itemsize, + **kwargs) for a in self.axes: a.validate(self, append) From 0a785d5a388ee9128b3e4996f66393dca47a5e9a Mon Sep 17 00:00:00 2001 From: Kyle Prestel Date: Sun, 11 Nov 2018 11:41:16 -0500 Subject: [PATCH 7/7] Revert changes to pass numeric_only --- pandas/core/groupby/groupby.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 0edba6f6b4f7f..ea7507799fa9a 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -1755,8 +1755,7 @@ def cummin(self, axis=0, **kwargs): if axis != 0: return self.apply(lambda x: np.minimum.accumulate(x, axis)) - return self._cython_transform('cummin', - numeric_only=kwargs.get('numeric_only') or False) + return self._cython_transform('cummin', numeric_only=False) @Substitution(name='groupby') @Appender(_doc_template) @@ -1765,8 +1764,7 @@ def cummax(self, axis=0, **kwargs): if axis != 0: return self.apply(lambda x: np.maximum.accumulate(x, axis)) - return self._cython_transform('cummax', - numeric_only=kwargs.get('numeric_only') or False) + return self._cython_transform('cummax', numeric_only=False) def _get_cythonized_result(self, how, grouper, aggregate=False, cython_dtype=None, needs_values=False,