Skip to content

Commit

Permalink
Rename agate.aggegators to agate.aggregations.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed Aug 30, 2015
1 parent f504d17 commit c50fbb5
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 23 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
-----

* Rename agate.aggegators to agate.aggregations.
* TableSet.to_csv implemented. (#195)
* TableSet.from_csv implemented. (#194)
* Table.to_csv implemented (#169)
Expand Down
2 changes: 1 addition & 1 deletion agate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

from agate.analysis import *
from agate.aggregators import *
from agate.aggregations import *
from agate.columns import *
from agate.column_types import *
from agate.computations import *
Expand Down
16 changes: 16 additions & 0 deletions agate/aggregators.py → agate/aggregations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#!/usr/bin/env python

"""
This module contains the :class:`Aggregation` class and its various subclasses.
Each of these classes processes a column's data and returns a single value. For
instance, :class:`Mean`, when applied to a :class:`.NumberColumn`, returns a
single :class:`decimal.Decimal` value which is the average of all values in that column.
Aggregations are applied to instances of :class:`.Column` using the
:meth:`.Column.aggregate` method. Typically, the column is first retrieved using
the :attr:`.Table.columns` attribute.
Aggregations can also be applied to instances of :class:`.TableSet` using the
:meth:`.Tableset.aggregate` method, in which case the result will be a new
:class:`.Table` with a column for each aggregation and a row for each table in
the set.
"""

from collections import defaultdict
import datetime

Expand Down
6 changes: 3 additions & 3 deletions agate/columns/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def __ne__(self, other):
"""
return not self.__eq__(other)

def aggregate(self, aggregator):
def aggregate(self, aggregation):
"""
Apply a :class:`.Aggregator` to this column and return the result.
Apply a :class:`.Aggregation` to this column and return the result.
"""
return aggregator.run(self)
return aggregation.run(self)
8 changes: 4 additions & 4 deletions agate/columns/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _sum(self):
"""
Compute the values in this column.
Should be invoked via the :class:`.Sum` aggregator.
Should be invoked via the :class:`.Sum` aggregation.
"""
return sum(self._data_without_nulls())

Expand All @@ -32,7 +32,7 @@ def _mean(self):
"""
Compute the mean of the values in this column.
Should be invoked via the :class:`.Mean` aggregator.
Should be invoked via the :class:`.Mean` aggregation.
"""
return self._sum() / len(self)

Expand All @@ -41,7 +41,7 @@ def _median(self):
"""
Compute the median of the values in this column.
Should be invoked via the :class:`.Median` aggregator.
Should be invoked via the :class:`.Median` aggregation.
"""
return self.percentiles()[50]

Expand All @@ -50,7 +50,7 @@ def _variance(self):
"""
Compute the median of the values in this column.
Should be invoked via the :class:`.Variance` aggregator.
Should be invoked via the :class:`.Variance` aggregation.
"""
data = self._data()
mean = self._mean()
Expand Down
2 changes: 1 addition & 1 deletion agate/computations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
columns.
"""

from agate.aggregators import Mean, StDev
from agate.aggregations import Mean, StDev
from agate.columns import NumberColumn
from agate.column_types import NumberType
from agate.exceptions import UnsupportedComputationError
Expand Down
2 changes: 1 addition & 1 deletion agate/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import six

from agate.aggregators import Sum, Mean, Median, StDev, MAD
from agate.aggregations import Sum, Mean, Median, StDev, MAD
from agate.columns.base import ColumnMapping
from agate.computations import Computation
from agate.exceptions import ColumnDoesNotExistError, RowDoesNotExistError
Expand Down
12 changes: 6 additions & 6 deletions agate/tableset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
except ImportError: # pragma: no cover
from ordereddict import OrderedDict

from agate.aggregators import Aggregation
from agate.aggregations import Aggregation
from agate.column_types import TextType, NumberType
from agate.exceptions import ColumnDoesNotExistError
from agate.rows import RowSequence
Expand Down Expand Up @@ -172,27 +172,27 @@ def aggregate(self, aggregations=[]):
:code:`new_column_name`.
:param aggregations: An list of triples in the format
:code:`(column_name, aggregator, new_column_name)`.
:code:`(column_name, aggregation, new_column_name)`.
:returns: A new :class:`.Table`.
"""
output = []

column_types = [TextType(), NumberType()]
column_names = ['group', 'count']

for column_name, aggregator, new_column_name in aggregations:
for column_name, aggregation, new_column_name in aggregations:
c = self._first_table.columns[column_name]

column_types.append(aggregator.get_aggregate_column_type(c))
column_types.append(aggregation.get_aggregate_column_type(c))
column_names.append(new_column_name)

for name, table in self._tables.items():
new_row = [name, len(table.rows)]

for column_name, aggregator, new_column_name in aggregations:
for column_name, aggregation, new_column_name in aggregations:
c = table.columns[column_name]

new_row.append(c.aggregate(aggregator))
new_row.append(c.aggregate(aggregation))

output.append(tuple(new_row))

Expand Down
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ API
.. toctree::
:maxdepth: 2

api/aggregators
api/aggregations
api/column_types
api/columns
api/computations
Expand Down
8 changes: 4 additions & 4 deletions docs/api/aggregators.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
======================
agate.aggregators
======================
==================
agate.aggregations
==================

.. automodule:: agate.aggregators
.. automodule:: agate.aggregations
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion tests/test_aggregators.py → tests/test_aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import unittest

from agate import Table
from agate.aggregators import *
from agate.aggregations import *
from agate.column_types import NumberType, TextType
from agate.exceptions import NullComputationError, UnsupportedAggregationError

Expand Down
2 changes: 1 addition & 1 deletion tests/test_tableset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import unittest

from agate import Table, TableSet
from agate.aggregators import *
from agate.aggregations import *
from agate.column_types import TextType, NumberType
from agate.computations import Formula
from agate.exceptions import ColumnDoesNotExistError
Expand Down

0 comments on commit c50fbb5

Please sign in to comment.