Made blank lines PEP-8 compatible

This commit is contained in:
Claude Paroz
2019-10-03 20:54:10 +02:00
parent 8cc024e61b
commit a0d19a56cb
6 changed files with 4 additions and 56 deletions
-1
View File
@@ -199,7 +199,6 @@ latex_use_parts = True
latex_additional_files = ['krstyle.sty'] latex_additional_files = ['krstyle.sty']
# The name of an image file (relative to this directory) to place at the top of # The name of an image file (relative to this directory) to place at the top of
# the title page. # the title page.
#latex_logo = None #latex_logo = None
+4 -50
View File
@@ -106,8 +106,6 @@ class Row(object):
return bool(len(set(tag) & set(self.tags))) return bool(len(set(tag) & set(self.tags)))
class Dataset(object): class Dataset(object):
"""The :class:`Dataset` object is the heart of Tablib. It provides all core """The :class:`Dataset` object is the heart of Tablib. It provides all core
functionality. functionality.
@@ -173,11 +171,9 @@ class Dataset(object):
self._register_formats() self._register_formats()
def __len__(self): def __len__(self):
return self.height return self.height
def __getitem__(self, key): def __getitem__(self, key):
if isinstance(key, (str, unicode)): if isinstance(key, (str, unicode)):
if key in self.headers: if key in self.headers:
@@ -196,7 +192,6 @@ class Dataset(object):
self._validate(value) self._validate(value)
self._data[key] = Row(value) self._data[key] = Row(value)
def __delitem__(self, key): def __delitem__(self, key):
if isinstance(key, (str, unicode)): if isinstance(key, (str, unicode)):
@@ -214,7 +209,6 @@ class Dataset(object):
else: else:
del self._data[key] del self._data[key]
def __repr__(self): def __repr__(self):
try: try:
return '<%s dataset>' % (self.title.lower()) return '<%s dataset>' % (self.title.lower())
@@ -267,7 +261,6 @@ class Dataset(object):
except AttributeError: except AttributeError:
cls._formats[fmt.title] = (None, None) cls._formats[fmt.title] = (None, None)
def _validate(self, row=None, col=None, safety=False): def _validate(self, row=None, col=None, safety=False):
"""Assures size of every row in dataset is of proper proportions.""" """Assures size of every row in dataset is of proper proportions."""
if row: if row:
@@ -287,7 +280,6 @@ class Dataset(object):
raise InvalidDimensions raise InvalidDimensions
return False return False
def _package(self, dicts=True, ordered=True): def _package(self, dicts=True, ordered=True):
"""Packages Dataset into lists of dictionaries for transmission.""" """Packages Dataset into lists of dictionaries for transmission."""
# TODO: Dicts default to false? # TODO: Dicts default to false?
@@ -312,7 +304,6 @@ class Dataset(object):
except IndexError: except IndexError:
raise InvalidDatasetIndex raise InvalidDatasetIndex
if self.headers: if self.headers:
if dicts: if dicts:
data = [dict_pack(list(zip(self.headers, data_row))) for data_row in _data] data = [dict_pack(list(zip(self.headers, data_row))) for data_row in _data]
@@ -323,8 +314,6 @@ class Dataset(object):
return data return data
def _get_headers(self): def _get_headers(self):
"""An *optional* list of strings to be used for header rows and attribute names. """An *optional* list of strings to be used for header rows and attribute names.
@@ -333,7 +322,6 @@ class Dataset(object):
""" """
return self.__headers return self.__headers
def _set_headers(self, collection): def _set_headers(self, collection):
"""Validating headers setter.""" """Validating headers setter."""
self._validate(collection) self._validate(collection)
@@ -347,7 +335,6 @@ class Dataset(object):
headers = property(_get_headers, _set_headers) headers = property(_get_headers, _set_headers)
def _get_dict(self): def _get_dict(self):
"""A native Python representation of the :class:`Dataset` object. If headers have """A native Python representation of the :class:`Dataset` object. If headers have
been set, a list of Python dictionaries will be returned. If no headers have been set, been set, a list of Python dictionaries will be returned. If no headers have been set,
@@ -361,7 +348,6 @@ class Dataset(object):
""" """
return self._package() return self._package()
def _set_dict(self, pickle): def _set_dict(self, pickle):
"""A native Python representation of the Dataset object. If headers have been """A native Python representation of the Dataset object. If headers have been
set, a list of Python dictionaries will be returned. If no headers have been set, a list of Python dictionaries will be returned. If no headers have been
@@ -394,7 +380,6 @@ class Dataset(object):
dict = property(_get_dict, _set_dict) dict = property(_get_dict, _set_dict)
def _clean_col(self, col): def _clean_col(self, col):
"""Prepares the given column for insert/append.""" """Prepares the given column for insert/append."""
@@ -412,7 +397,6 @@ class Dataset(object):
return col return col
@property @property
def height(self): def height(self):
"""The number of rows currently in the :class:`Dataset`. """The number of rows currently in the :class:`Dataset`.
@@ -420,7 +404,6 @@ class Dataset(object):
""" """
return len(self._data) return len(self._data)
@property @property
def width(self): def width(self):
"""The number of columns currently in the :class:`Dataset`. """The number of columns currently in the :class:`Dataset`.
@@ -435,7 +418,6 @@ class Dataset(object):
except TypeError: except TypeError:
return 0 return 0
def load(self, in_stream, format=None, **kwargs): def load(self, in_stream, format=None, **kwargs):
""" """
Import `in_stream` to the :class:`Dataset` object using the `format`. Import `in_stream` to the :class:`Dataset` object using the `format`.
@@ -453,8 +435,6 @@ class Dataset(object):
import_set(self, in_stream, **kwargs) import_set(self, in_stream, **kwargs)
return self return self
def export(self, format, **kwargs): def export(self, format, **kwargs):
""" """
Export :class:`Dataset` object to `format`. Export :class:`Dataset` object to `format`.
@@ -552,7 +532,6 @@ class Dataset(object):
""" """
pass pass
@property @property
def tsv(): def tsv():
"""A TSV representation of the :class:`Dataset` object. The top row will contain """A TSV representation of the :class:`Dataset` object. The top row will contain
@@ -677,7 +656,6 @@ class Dataset(object):
self._validate(row) self._validate(row)
self._data.insert(index, Row(row, tags=tags)) self._data.insert(index, Row(row, tags=tags))
def rpush(self, row, tags=list()): def rpush(self, row, tags=list()):
"""Adds a row to the end of the :class:`Dataset`. """Adds a row to the end of the :class:`Dataset`.
See :class:`Dataset.insert` for additional documentation. See :class:`Dataset.insert` for additional documentation.
@@ -685,7 +663,6 @@ class Dataset(object):
self.insert(self.height, row=row, tags=tags) self.insert(self.height, row=row, tags=tags)
def lpush(self, row, tags=list()): def lpush(self, row, tags=list()):
"""Adds a row to the top of the :class:`Dataset`. """Adds a row to the top of the :class:`Dataset`.
See :class:`Dataset.insert` for additional documentation. See :class:`Dataset.insert` for additional documentation.
@@ -693,7 +670,6 @@ class Dataset(object):
self.insert(0, row=row, tags=tags) self.insert(0, row=row, tags=tags)
def append(self, row, tags=list()): def append(self, row, tags=list()):
"""Adds a row to the :class:`Dataset`. """Adds a row to the :class:`Dataset`.
See :class:`Dataset.insert` for additional documentation. See :class:`Dataset.insert` for additional documentation.
@@ -709,7 +685,6 @@ class Dataset(object):
for row in rows: for row in rows:
self.append(row, tags) self.append(row, tags)
def lpop(self): def lpop(self):
"""Removes and returns the first row of the :class:`Dataset`.""" """Removes and returns the first row of the :class:`Dataset`."""
@@ -718,7 +693,6 @@ class Dataset(object):
return cache return cache
def rpop(self): def rpop(self):
"""Removes and returns the last row of the :class:`Dataset`.""" """Removes and returns the last row of the :class:`Dataset`."""
@@ -727,13 +701,11 @@ class Dataset(object):
return cache return cache
def pop(self): def pop(self):
"""Removes and returns the last row of the :class:`Dataset`.""" """Removes and returns the last row of the :class:`Dataset`."""
return self.rpop() return self.rpop()
# ------- # -------
# Columns # Columns
# ------- # -------
@@ -788,7 +760,6 @@ class Dataset(object):
self.headers.insert(index, header) self.headers.insert(index, header)
if self.height and self.width: if self.height and self.width:
for i, row in enumerate(self._data): for i, row in enumerate(self._data):
@@ -798,8 +769,6 @@ class Dataset(object):
else: else:
self._data = [Row([row]) for row in col] self._data = [Row([row]) for row in col]
def rpush_col(self, col, header=None): def rpush_col(self, col, header=None):
"""Adds a column to the end of the :class:`Dataset`. """Adds a column to the end of the :class:`Dataset`.
See :class:`Dataset.insert` for additional documentation. See :class:`Dataset.insert` for additional documentation.
@@ -807,7 +776,6 @@ class Dataset(object):
self.insert_col(self.width, col, header=header) self.insert_col(self.width, col, header=header)
def lpush_col(self, col, header=None): def lpush_col(self, col, header=None):
"""Adds a column to the top of the :class:`Dataset`. """Adds a column to the top of the :class:`Dataset`.
See :class:`Dataset.insert` for additional documentation. See :class:`Dataset.insert` for additional documentation.
@@ -815,14 +783,12 @@ class Dataset(object):
self.insert_col(0, col, header=header) self.insert_col(0, col, header=header)
def insert_separator(self, index, text='-'): def insert_separator(self, index, text='-'):
"""Adds a separator to :class:`Dataset` at given index.""" """Adds a separator to :class:`Dataset` at given index."""
sep = (index, text) sep = (index, text)
self._separators.append(sep) self._separators.append(sep)
def append_separator(self, text='-'): def append_separator(self, text='-'):
"""Adds a :ref:`separator <separators>` to the :class:`Dataset`.""" """Adds a :ref:`separator <separators>` to the :class:`Dataset`."""
@@ -834,7 +800,6 @@ class Dataset(object):
self.insert_separator(index, text) self.insert_separator(index, text)
def append_col(self, col, header=None): def append_col(self, col, header=None):
"""Adds a column to the :class:`Dataset`. """Adds a column to the :class:`Dataset`.
See :class:`Dataset.insert_col` for additional documentation. See :class:`Dataset.insert_col` for additional documentation.
@@ -842,13 +807,11 @@ class Dataset(object):
self.rpush_col(col, header) self.rpush_col(col, header)
def get_col(self, index): def get_col(self, index):
"""Returns the column from the :class:`Dataset` at the given index.""" """Returns the column from the :class:`Dataset` at the given index."""
return [row[index] for row in self._data] return [row[index] for row in self._data]
# ---- # ----
# Misc # Misc
# ---- # ----
@@ -875,7 +838,6 @@ class Dataset(object):
return True return True
def filter(self, tag): def filter(self, tag):
"""Returns a new instance of the :class:`Dataset`, excluding any rows """Returns a new instance of the :class:`Dataset`, excluding any rows
that do not contain the given :ref:`tags <tags>`. that do not contain the given :ref:`tags <tags>`.
@@ -885,7 +847,6 @@ class Dataset(object):
return _dset return _dset
def sort(self, col, reverse=False): def sort(self, col, reverse=False):
"""Sort a :class:`Dataset` by a specific column, given string (for """Sort a :class:`Dataset` by a specific column, given string (for
header) or integer (for column index). The order can be reversed by header) or integer (for column index). The order can be reversed by
@@ -921,10 +882,8 @@ class Dataset(object):
row = item row = item
_dset.append(row=row) _dset.append(row=row)
return _dset return _dset
def transpose(self): def transpose(self):
"""Transpose a :class:`Dataset`, turning rows into columns and vice """Transpose a :class:`Dataset`, turning rows into columns and vice
versa, returning a new ``Dataset`` instance. The first row of the versa, returning a new ``Dataset`` instance. The first row of the
@@ -953,7 +912,6 @@ class Dataset(object):
_dset.append(row=row_data) _dset.append(row=row_data)
return _dset return _dset
def stack(self, other): def stack(self, other):
"""Stack two :class:`Dataset` instances together by """Stack two :class:`Dataset` instances together by
joining at the row level, and return new combined joining at the row level, and return new combined
@@ -976,7 +934,6 @@ class Dataset(object):
return _dset return _dset
def stack_cols(self, other): def stack_cols(self, other):
"""Stack two :class:`Dataset` instances together by """Stack two :class:`Dataset` instances together by
joining at the column level, and return a new joining at the column level, and return a new
@@ -1010,20 +967,17 @@ class Dataset(object):
return _dset return _dset
def remove_duplicates(self): def remove_duplicates(self):
"""Removes all duplicate rows from the :class:`Dataset` object """Removes all duplicate rows from the :class:`Dataset` object
while maintaining the original order.""" while maintaining the original order."""
seen = set() seen = set()
self._data[:] = [row for row in self._data if not (tuple(row) in seen or seen.add(tuple(row)))] self._data[:] = [row for row in self._data if not (tuple(row) in seen or seen.add(tuple(row)))]
def wipe(self): def wipe(self):
"""Removes all content and headers from the :class:`Dataset` object.""" """Removes all content and headers from the :class:`Dataset` object."""
self._data = list() self._data = list()
self.__headers = None self.__headers = None
def subset(self, rows=None, cols=None): def subset(self, rows=None, cols=None):
"""Returns a new instance of the :class:`Dataset`, """Returns a new instance of the :class:`Dataset`,
including only specified rows and columns. including only specified rows and columns.
@@ -1064,7 +1018,6 @@ class Dataset(object):
return _dset return _dset
class Databook(object): class Databook(object):
"""A book of :class:`Dataset` objects. """A book of :class:`Dataset` objects.
""" """
@@ -1090,7 +1043,6 @@ class Databook(object):
"""Removes all :class:`Dataset` objects from the :class:`Databook`.""" """Removes all :class:`Dataset` objects from the :class:`Databook`."""
self._datasets = [] self._datasets = []
@classmethod @classmethod
def _register_formats(cls): def _register_formats(cls):
"""Adds format properties.""" """Adds format properties."""
@@ -1116,7 +1068,6 @@ class Databook(object):
else: else:
raise InvalidDatasetType raise InvalidDatasetType
def _package(self, ordered=True): def _package(self, ordered=True):
"""Packages :class:`Databook` for delivery.""" """Packages :class:`Databook` for delivery."""
collector = [] collector = []
@@ -1133,7 +1084,6 @@ class Databook(object):
)) ))
return collector return collector
@property @property
def size(self): def size(self):
"""The number of the :class:`Dataset` objects within :class:`Databook`.""" """The number of the :class:`Dataset` objects within :class:`Databook`."""
@@ -1178,6 +1128,7 @@ def detect_format(stream):
except AttributeError: except AttributeError:
pass pass
def import_set(stream, format=None, **kwargs): def import_set(stream, format=None, **kwargs):
"""Return dataset of given stream.""" """Return dataset of given stream."""
@@ -1197,11 +1148,14 @@ class InvalidDatasetType(Exception):
class InvalidDimensions(Exception): class InvalidDimensions(Exception):
"Invalid size" "Invalid size"
class InvalidDatasetIndex(Exception): class InvalidDatasetIndex(Exception):
"Outside of Dataset size" "Outside of Dataset size"
class HeadersNeeded(Exception): class HeadersNeeded(Exception):
"Header parameter must be given when appending a column in this Dataset." "Header parameter must be given when appending a column in this Dataset."
class UnsupportedFormat(NotImplementedError): class UnsupportedFormat(NotImplementedError):
"Format is not supported" "Format is not supported"
-1
View File
@@ -38,7 +38,6 @@ def export_book(databook):
wb.spreadsheet.addElement(ws) wb.spreadsheet.addElement(ws)
dset_sheet(dset, ws) dset_sheet(dset, ws)
stream = BytesIO() stream = BytesIO()
wb.save(stream) wb.save(stream)
return stream.getvalue() return stream.getvalue()
-2
View File
@@ -61,7 +61,6 @@ def export_book(databook):
dset_sheet(dset, ws) dset_sheet(dset, ws)
stream = BytesIO() stream = BytesIO()
wb.save(stream) wb.save(stream)
return stream.getvalue() return stream.getvalue()
@@ -122,7 +121,6 @@ def dset_sheet(dataset, ws):
ws.panes_frozen = True ws.panes_frozen = True
ws.horz_split_pos = 1 ws.horz_split_pos = 1
# bold separators # bold separators
elif len(row) < dataset.width: elif len(row) < dataset.width:
ws.write(i, j, col, bold) ws.write(i, j, col, bold)
-1
View File
@@ -59,7 +59,6 @@ def export_book(databook, freeze_panes=True):
dset_sheet(dset, ws, freeze_panes=freeze_panes) dset_sheet(dset, ws, freeze_panes=freeze_panes)
stream = BytesIO() stream = BytesIO()
wb.save(stream) wb.save(stream)
return stream.getvalue() return stream.getvalue()
-1
View File
@@ -56,7 +56,6 @@ class DbfFieldDef(object):
""" """
__slots__ = ("name", "decimalCount", __slots__ = ("name", "decimalCount",
"start", "end", "ignoreErrors") "start", "end", "ignoreErrors")