Skip to content

Commit

Permalink
Fix active deepsource issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ynop committed Apr 16, 2020
1 parent 2ad035a commit 14b2ae2
Show file tree
Hide file tree
Showing 80 changed files with 883 additions and 752 deletions.
3 changes: 2 additions & 1 deletion audiomate/annotations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
This module contains classes to describe the content of an audio-segment.
This module contains classes to describe
the content of an audio-segment.
"""

from .label import Label # noqa: F401
Expand Down
10 changes: 3 additions & 7 deletions audiomate/annotations/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


@total_ordering
class Label(object):
class Label:
"""
Represents a label that describes some part of an utterance.
Expand Down Expand Up @@ -90,16 +90,12 @@ def end_abs(self):

@property
def duration(self):
"""
Return the duration of the label in seconds.
"""
""" Return the duration of the label in seconds. """
return self.end_abs - self.start_abs

@property
def length(self):
"""
Return the length of the label (Number of characters).
"""
""" Return the length of the label (Number of characters). """
return len(self.value)

def read_samples(self, sr=None):
Expand Down
75 changes: 42 additions & 33 deletions audiomate/annotations/label_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .label import Label


class LabelList(object):
class LabelList:
"""
Represents a list of labels which describe an utterance.
An utterance can have multiple label-lists.
Expand Down Expand Up @@ -86,9 +86,10 @@ def end(self):
@property
def total_length(self):
"""
Return the cumulative length of all labels. (Number of characters)
Return the cumulative length of all labels
(Number of characters).
"""
return sum([label.length for label in self.labels])
return sum(label.length for label in self.labels)

#
# Alteration
Expand All @@ -105,9 +106,7 @@ def add(self, label):
self.label_tree.addi(label.start, label.end, label)

def addl(self, value, start=0.0, end=float('inf')):
"""
Shortcut for ``add(Label(value, start, end))``.
"""
""" Shortcut for ``add(Label(value, start, end))``. """
self.add(Label(value, start=start, end=end))

def update(self, labels):
Expand Down Expand Up @@ -226,7 +225,8 @@ def recursive_overlaps(interval):

def label_total_duration(self):
"""
Return for each distinct label value the total duration of all occurrences.
Return for each distinct label value the total duration of
all occurrences.
Returns:
dict: A dictionary containing for every label-value (key)
Expand Down Expand Up @@ -270,7 +270,7 @@ def label_values(self):
['a', 'b', 'c', 'd']
"""

all_labels = set([l.value for l in self])
all_labels = {l.value for l in self}
return sorted(all_labels)

def label_count(self):
Expand Down Expand Up @@ -305,8 +305,8 @@ def all_tokens(self, delimiter=' '):
Return a list of all tokens occurring in the label-list.
Args:
delimiter (str): The delimiter used to split labels into tokens
(see :meth:`audiomate.annotations.Label.tokenized`).
delimiter (str): The delimiter used to split labels into tokens.
See :meth:`audiomate.annotations.Label.tokenized`
Returns:
:class:`set`: A set of distinct tokens.
Expand All @@ -326,12 +326,13 @@ def join(self, delimiter=' ', overlap_threshold=0.1):
"""
Return a string with all labels concatenated together.
The order of the labels is defined by the start of the label.
If the overlapping between two labels is greater than ``overlap_threshold``,
an Exception is thrown.
If the overlapping between two labels is greater than
``overlap_threshold``, an Exception is thrown.
Args:
delimiter (str): A string to join two consecutive labels.
overlap_threshold (float): Maximum overlap between two consecutive labels.
overlap_threshold (float): Maximum overlap between two
consecutive labels.
Returns:
str: A string with all labels concatenated together.
Expand Down Expand Up @@ -364,15 +365,18 @@ def tokenized(self, delimiter=' ', overlap_threshold=0.1):
"""
Return a ordered list of tokens based on all labels.
Joins all token from all labels (``label.tokenized()```).
If the overlapping between two labels is greater than ``overlap_threshold``,
an Exception is thrown.
If the overlapping between two labels is greater than
``overlap_threshold``, an Exception is thrown.
Args:
delimiter (str): The delimiter used to split labels into tokens. (default: space)
overlap_threshold (float): Maximum overlap between two consecutive labels.
delimiter (str): The delimiter used to split labels into tokens.
(default: space)
overlap_threshold (float): Maximum overlap between two
consecutive labels.
Returns:
str: A list containing tokens of all labels ordered according to the label order.
str: A list containing tokens of all labels ordered according
to the label order.
Example:
>>> ll = LabelList(idx='some', labels=[
Expand Down Expand Up @@ -407,8 +411,8 @@ def separated(self):
Create a separate Label-List for every distinct label-value.
Returns:
dict: A dictionary with distinct label-values as keys.
Every value is a LabelList containing only labels with the same value.
dict: A dictionary with distinct label-values as keys. Every value
is a LabelList containing only labels with the same value.
Example:
>>> ll = LabelList(idx='some', labels=[
Expand Down Expand Up @@ -518,8 +522,7 @@ def reduce(x, y):
last_end = intervals[0].begin

# yield range by range
for i in range(len(intervals)):
iv = intervals[i]
for iv in intervals:

# yield an empty range if necessary
if yield_ranges_without_labels and iv.begin > last_end:
Expand All @@ -532,21 +535,24 @@ def reduce(x, y):
def split(self, cutting_points, shift_times=False, overlap=0.0):
"""
Split the label-list into x parts and return them as new label-lists.
x is defined by the number of cutting-points(``x == len(cutting_points) + 1``)
x is defined by the number of cutting-points
(``x == len(cutting_points) + 1``).
The result is a list of label-lists corresponding to each part.
Label-list 0 contains labels between ``0`` and ``cutting_points[0]``.
Label-list 1 contains labels between ``cutting_points[0]`` and ``cutting_points[1]``.
And so on.
Label-list 1 contains labels between ``cutting_points[0]`` and
``cutting_points[1]``. And so on.
Args:
cutting_points(list): List of floats defining the points in seconds,
where the label-list is splitted.
shift_times(bool): If True, start and end-time are shifted in splitted label-lists.
So the start is relative to the cutting point and
not to the beginning of the original label-list.
overlap(float): Amount of overlap in seconds. This amount is subtracted
from a start-cutting-point, and added to a end-cutting-point.
shift_times(bool): If True, start and end-time are shifted in
splitted label-lists. So the start is relative
to the cutting point and not to the beginning
of the original label-list.
overlap(float): Amount of overlap in seconds. This amount is
subtracted from a start-cutting-point, and added
to a end-cutting-point.
Returns:
list: A list of of: class: `audiomate.annotations.LabelList`.
Expand Down Expand Up @@ -644,7 +650,10 @@ def split(self, cutting_points, shift_times=False, overlap=0.0):

@classmethod
def create_single(cls, value, idx='default'):
""" Create a label-list with a single label containing the given value. """
"""
Create a label-list with a single label
containing the given value.
"""

return LabelList(idx=idx, labels=[
Label(value=value)
Expand All @@ -657,8 +666,8 @@ def with_label_values(cls, values, idx='default'):
All labels will have default start/end values of 0 and ``inf``.
Args:
values(list): List of values(str) that should be created and appended
to the label-list.
values(list): List of values(str) that should be created and
appended to the label-list.
idx(str): The idx of the label-list.
Returns:
Expand Down
3 changes: 2 additions & 1 deletion audiomate/annotations/relabeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@


class UnmappedLabelsException(Exception):

def __init__(self, message):
super(Exception, self).__init__(message)
super(UnmappedLabelsException, self).__init__(message)
self.message = message


Expand Down
4 changes: 4 additions & 0 deletions audiomate/containers/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def get(self, key, mem_map=True):

return data, sampling_rate

return None

# skipcq: PYL-W0221
def set(self, key, samples, sampling_rate):
"""
Set the samples and sampling-rate for the given key.
Expand Down Expand Up @@ -76,6 +79,7 @@ def set(self, key, samples, sampling_rate):
dset = self._file.create_dataset(key, data=samples)
dset.attrs[SAMPLING_RATE_ATTR] = sampling_rate

# skipcq: PYL-W0221
def append(self, key, samples, sampling_rate):
"""
Append the given samples to the data that already exists
Expand Down
11 changes: 5 additions & 6 deletions audiomate/containers/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import h5py


class Container(object):
class Container:
"""
A container is a wrapper around a HDF5 file.
In a container is used to store array-like data.
Expand Down Expand Up @@ -51,16 +51,15 @@ def open(self, mode=None):
self._file = h5py.File(self.path, mode=mode)

def close(self):
"""
Close the container file if its open.
"""
""" Close the container file if its open. """
if self._file is not None:
self._file.close()
self._file = None

def is_open(self, mode=None):
def is_open(self):
"""
Return ``True``, if container is already open. ``False`` otherwise.
Return ``True``, if container is already open.
``False`` otherwise.
"""
return self._file is not None

Expand Down

0 comments on commit 14b2ae2

Please sign in to comment.