summaryrefslogtreecommitdiff
path: root/django/contrib/postgres
diff options
context:
space:
mode:
authorTom <tom@tomforb.es>2017-04-22 16:44:51 +0100
committerTim Graham <timograham@gmail.com>2017-08-12 17:58:28 -0400
commitb78d100fa62cd4fbbc70f2bae77c192cb36c1ccd (patch)
treebe1f272298c15c6a261e33dff7486b0c3727b407 /django/contrib/postgres
parent489421b01562494ab506de5d30ea97d7b6b5df30 (diff)
Fixed #27849 -- Added filtering support to aggregates.
Diffstat (limited to 'django/contrib/postgres')
-rw-r--r--django/contrib/postgres/aggregates/statistics.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/django/contrib/postgres/aggregates/statistics.py b/django/contrib/postgres/aggregates/statistics.py
index b9a8ba07c5..19f26ec53c 100644
--- a/django/contrib/postgres/aggregates/statistics.py
+++ b/django/contrib/postgres/aggregates/statistics.py
@@ -8,10 +8,10 @@ __all__ = [
class StatAggregate(Aggregate):
- def __init__(self, y, x, output_field=FloatField()):
+ def __init__(self, y, x, output_field=FloatField(), filter=None):
if not x or not y:
raise ValueError('Both y and x must be provided.')
- super().__init__(y, x, output_field=output_field)
+ super().__init__(y, x, output_field=output_field, filter=filter)
def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
return super().resolve_expression(query, allow_joins, reuse, summarize)
@@ -22,9 +22,9 @@ class Corr(StatAggregate):
class CovarPop(StatAggregate):
- def __init__(self, y, x, sample=False):
+ def __init__(self, y, x, sample=False, filter=None):
self.function = 'COVAR_SAMP' if sample else 'COVAR_POP'
- super().__init__(y, x)
+ super().__init__(y, x, filter=filter)
class RegrAvgX(StatAggregate):
@@ -38,8 +38,8 @@ class RegrAvgY(StatAggregate):
class RegrCount(StatAggregate):
function = 'REGR_COUNT'
- def __init__(self, y, x):
- super().__init__(y=y, x=x, output_field=IntegerField())
+ def __init__(self, y, x, filter=None):
+ super().__init__(y=y, x=x, output_field=IntegerField(), filter=filter)
def convert_value(self, value, expression, connection):
if value is None: