Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for TimeDelta to Mean #762

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('Mean can only be applied to columns containing Number or TimeDelta data.')

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

Expand Down
14 changes: 10 additions & 4 deletions agate/computations/slug.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
from agate.exceptions import DataTypeError
from agate.utils import issequence, slugify

def denonify(v):
if v == None:
return ''
return v


class Slug(Computation):
"""
Expand Down Expand Up @@ -40,8 +45,9 @@ def validate(self, table):
if not isinstance(column.data_type, Text):
raise DataTypeError('Slug column must contain Text data.')

if HasNulls(column_name).run(table):
raise ValueError('Slug column cannot contain `None`.')
# JOSH CHANGE: Sure a slug can have None. We'll just replace it with an empty string.
# if HasNulls(column_name).run(table):
# raise ValueError('Slug column cannot contain `None`.')

def run(self, table):
"""
Expand All @@ -54,10 +60,10 @@ def run(self, table):
if issequence(self._column_name):
column_value = ''
for column_name in self._column_name:
column_value = column_value + ' ' + row[column_name]
column_value = column_value + ' ' + denonify(row[column_name])

new_column.append(column_value)
else:
new_column.append(row[self._column_name])
new_column.append(denonify(row[self._column_name]))

return slugify(new_column, ensure_unique=self._ensure_unique, **self._slug_args)