Skip to content

Commit

Permalink
Merge pull request #28 from PickwickSoft/deepsource-config
Browse files Browse the repository at this point in the history
Add docstrings
  • Loading branch information
garlontas authored Jun 3, 2023
2 parents e447039 + 7194522 commit 45c8905
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pystreamapi/_streams/numeric/__numeric_base_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@


class NumericBaseStream(BaseStream, ABC):
"""
This stream extends the capabilities of the default stream by introducing numerical operations.
It is designed specifically for use with numerical data sources and can only be applied
to such data.
"""

def interquartile_range(self) -> Union[float, int, None]:
"""
Expand Down Expand Up @@ -41,6 +46,7 @@ def median(self) -> Union[float, int, None]:

@staticmethod
def __median(source) -> Union[float, int, None]:
"""Calculates the median of a numerical Stream"""
source = sorted(source)
if not source:
return None
Expand Down
3 changes: 3 additions & 0 deletions pystreamapi/_streams/numeric/__parallel_numeric_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@


class ParallelNumericStream(NumericBaseStream, ParallelStream):
"""Numeric Stream with parallel implementation"""

def mean(self) -> Union[float, int, None]:
"""Calculates mean of values"""
self._trigger_exec()
return self.__sum() / len(self._source) if len(self._source) > 0 else None

def __sum(self):
"""Parallel sum method"""
self._set_parallelizer_src()
return self.parallelizer.reduce(lambda x, y: x + y)
2 changes: 2 additions & 0 deletions pystreamapi/_streams/numeric/__sequential_numeric_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@


class SequentialNumericStream(NumericBaseStream, SequentialStream):
"""Numeric Stream with sequential implementation"""

def mean(self) -> Union[float, int, None]:
"""Calculates mean of values"""
self._trigger_exec()
return sum(self._source) / len(self._source) if len(self._source) > 0 else None

0 comments on commit 45c8905

Please sign in to comment.