numpy: fix flake8 warnings
@@ -10,14 +10,15 @@ from ..backend import json
__all__ = ['register_handlers', 'unregister_handlers']
-class PandasProcessor():
+
+class PandasProcessor(object):
def __init__(self, size_threshold=500, compression=zlib):
"""
:param size_threshold: nonnegative int or None
valid values for 'size_threshold' are all nonnegative
- integers and None
- if size_threshold is None, dataframes are always stored as csv strings
+ integers and None. If size_threshold is None,
+ dataframes are always stored as csv strings
:param compression: a compression module or None
valid values for 'compression' are {zlib, bz2, None}
if compresion is None, no compression is applied
@@ -48,7 +49,7 @@ class PandasProcessor():
if data.get('comp', False):
buf = self.compression.decompress(buf).decode()
meta = data.get('meta', {})
- return buf,meta
+ return (buf, meta)
class PandasDfHandler(BaseHandler):
@@ -64,16 +65,20 @@ class PandasDfHandler(BaseHandler):
def restore(self, data):
csv, meta = self.pp.restore_pandas(data)
dtype = meta['dtypes'] if 'dtypes' in meta else None
- df = pd.read_csv(StringIO(csv), index_col=meta.get('index_col', None), dtype=dtype)
+ df = pd.read_csv(StringIO(csv),
+ index_col=meta.get('index_col', None),
+ dtype=dtype)
return df
+
class PandasSeriesHandler(BaseHandler):
pp = PandasProcessor()
def flatten(self, obj, data):
dtypes = {k: str(pd.np.dtype(type(obj[k]))) for k in obj.keys()}
meta = {'dtypes': dtypes, 'name': obj.name}
- # Save series as two rows rather than two cols to make preserving type easier
+ # Save series as two rows rather than two cols to make preserving the
+ # type easier.
data = self.pp.flatten_pandas(obj.to_frame().T.to_csv(), data, meta)
return data
@@ -81,9 +86,12 @@ class PandasSeriesHandler(BaseHandler):
csv, meta = self.pp.restore_pandas(data)
dtypes = meta['dtypes'] if 'dtypes' in meta else None
df = pd.read_csv(StringIO(csv), dtype=dtypes)
- ser = pd.Series(data=df.iloc[:,1:].values[0], index=df.columns[1:].values, name=meta.get('name', None))
+ ser = pd.Series(data=df.iloc[:, 1:].values[0],
+ index=df.columns[1:].values,
+ name=meta.get('name', None))
return ser
+
class PandasIndexHandler(BaseHandler):
pp = PandasProcessor()
@@ -111,4 +119,3 @@ def unregister_handlers():
unregister(pd.DataFrame)
unregister(pd.Series)
unregister(pd.Index)
-
