Skip to content

Commit

Permalink
Remove unnecessary NonNullAggregation.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed Aug 30, 2015
1 parent c973f8f commit 0c220a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
0.6.0
-----

* NonNullAggregation class removed.
* Some private Column methods made public. (#183)
* Rename agate.aggegators to agate.aggregations.
* TableSet.to_csv implemented. (#195)
Expand Down
58 changes: 28 additions & 30 deletions agate/aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ def run(self, column):
"""
raise NotImplementedError()

class NonNullAggregation(Aggregation):
"""
Raise a :exc:`.NullComputationError` if the column this aggregation is
being applied to contains null values.
"""
def run(self, column):
if column.has_nulls():
raise NullComputationError

class HasNulls(Aggregation):
"""
Returns :code:`True` if the column contains null values.
Expand Down Expand Up @@ -198,7 +189,7 @@ def run(self, column):

return column.sum()

class Mean(NonNullAggregation):
class Mean(Aggregation):
"""
Compute the mean value of a column.
"""
Expand All @@ -209,14 +200,15 @@ def run(self, column):
"""
:returns: :class:`decimal.Decimal`.
"""
super(Mean, self).run(column)

if not isinstance(column, NumberColumn):
raise UnsupportedAggregationError(self, column)

if column.has_nulls():
raise NullComputationError

return column.mean()

class Median(NonNullAggregation):
class Median(Aggregation):
"""
Compute the median value of a column.
Expand All @@ -230,14 +222,15 @@ def run(self, column):
"""
:returns: :class:`decimal.Decimal`.
"""
super(Median, self).run(column)

if not isinstance(column, NumberColumn):
raise UnsupportedAggregationError(self, column)

if column.has_nulls():
raise NullComputationError

return column.median()

class Mode(NonNullAggregation):
class Mode(Aggregation):
"""
Compute the mode value of a column.
"""
Expand All @@ -248,11 +241,12 @@ def run(self, column):
"""
:returns: :class:`decimal.Decimal`.
"""
super(Mode, self).run(column)

if not isinstance(column, NumberColumn):
raise UnsupportedAggregationError(self, column)

if column.has_nulls():
raise NullComputationError

data = column.get_data()
state = defaultdict(int)

Expand All @@ -261,7 +255,7 @@ def run(self, column):

return max(state.keys(), key=lambda x: state[x])

class IQR(NonNullAggregation):
class IQR(Aggregation):
"""
Compute the inter-quartile range of a column.
"""
Expand All @@ -272,16 +266,17 @@ def run(self, column):
"""
:returns: :class:`decimal.Decimal`.
"""
super(IQR, self).run(column)

if not isinstance(column, NumberColumn):
raise UnsupportedAggregationError(self, column)

if column.has_nulls():
raise NullComputationError

percentiles = column.percentiles()

return percentiles[75] - percentiles[25]

class Variance(NonNullAggregation):
class Variance(Aggregation):
"""
Compute the variance of a column.
"""
Expand All @@ -292,14 +287,15 @@ def run(self, column):
"""
:returns: :class:`decimal.Decimal`.
"""
super(Variance, self).run(column)

if not isinstance(column, NumberColumn):
raise UnsupportedAggregationError(self, column)

if column.has_nulls():
raise NullComputationError

return column.variance()

class StDev(NonNullAggregation):
class StDev(Aggregation):
"""
Compute the standard of deviation of a column.
"""
Expand All @@ -310,14 +306,15 @@ def run(self, column):
"""
:returns: :class:`decimal.Decimal`.
"""
super(StDev, self).run(column)

if not isinstance(column, NumberColumn):
raise UnsupportedAggregationError(self, column)

if column.has_nulls():
raise NullComputationError

return column.variance().sqrt()

class MAD(NonNullAggregation):
class MAD(Aggregation):
"""
Compute the `median absolute deviation <http://en.wikipedia.org/wiki/Median_absolute_deviation>`_
of a column.
Expand All @@ -341,11 +338,12 @@ def run(self, column):
"""
:returns: :class:`decimal.Decimal`.
"""
super(MAD, self).run(column)

if not isinstance(column, NumberColumn):
raise UnsupportedAggregationError(self, column)

if column.has_nulls():
raise NullComputationError

data = column.get_data_sorted()
m = column.percentiles()[50]

Expand Down

0 comments on commit 0c220a9

Please sign in to comment.