Skip to content

Commit

Permalink
Potential revision for mean.py to add support for TimeDelta. wireserv…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirkman committed Oct 6, 2021
1 parent 9b12d4b commit 5df10d1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions agate/aggregations/mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from agate.aggregations.base import Aggregation
from agate.aggregations.has_nulls import HasNulls
from agate.aggregations.sum import Sum
from agate.data_types import Number
from agate.data_types import Number, TimeDelta
from agate.exceptions import DataTypeError
from agate.warns import warn_null_calculation

Expand All @@ -20,13 +20,16 @@ def __init__(self, column_name):
self._sum = Sum(column_name)

def get_aggregate_data_type(self, table):
return Number()
column = table.columns[self._column_name]

if isinstance(column.data_type, (Number, TimeDelta)):
return column.data_type

def validate(self, table):
column = table.columns[self._column_name]

if not isinstance(column.data_type, Number):
raise DataTypeError('Mean can only be applied to columns containing Number data.')
if not isinstance(column.data_type, (Number, TimeDelta)):
raise DataTypeError('Sum can only be applied to columns containing Number or TimeDelta data.')

has_nulls = HasNulls(self._column_name).run(table)

Expand Down

0 comments on commit 5df10d1

Please sign in to comment.