initial commit
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
from .general import * # NOQA
|
||||
from .statistics import * # NOQA
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+107
@@ -0,0 +1,107 @@
|
||||
import warnings
|
||||
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
from django.db.models import Aggregate
|
||||
from django.db.models import BitAnd as _BitAnd
|
||||
from django.db.models import BitOr as _BitOr
|
||||
from django.db.models import BitXor as _BitXor
|
||||
from django.db.models import BooleanField, JSONField
|
||||
from django.db.models import StringAgg as _StringAgg
|
||||
from django.db.models import Value
|
||||
from django.utils.deprecation import RemovedInDjango70Warning
|
||||
|
||||
__all__ = [
|
||||
"ArrayAgg",
|
||||
"BitAnd", # RemovedInDjango70Warning
|
||||
"BitOr", # RemovedInDjango70Warning
|
||||
"BitXor", # RemovedInDjango70Warning
|
||||
"BoolAnd",
|
||||
"BoolOr",
|
||||
"JSONBAgg",
|
||||
"StringAgg", # RemovedInDjango70Warning.
|
||||
]
|
||||
|
||||
|
||||
class ArrayAgg(Aggregate):
|
||||
function = "ARRAY_AGG"
|
||||
allow_distinct = True
|
||||
allow_order_by = True
|
||||
|
||||
@property
|
||||
def output_field(self):
|
||||
return ArrayField(self.source_expressions[0].output_field)
|
||||
|
||||
|
||||
class BitAnd(_BitAnd):
|
||||
def __init__(self, expression, **extra):
|
||||
warnings.warn(
|
||||
"The PostgreSQL-specific BitAnd function is deprecated. Use "
|
||||
"django.db.models.aggregates.BitAnd instead.",
|
||||
category=RemovedInDjango70Warning,
|
||||
stacklevel=2,
|
||||
)
|
||||
super().__init__(expression, **extra)
|
||||
|
||||
|
||||
class BitOr(_BitOr):
|
||||
def __init__(self, expression, **extra):
|
||||
warnings.warn(
|
||||
"The PostgreSQL-specific BitOr function is deprecated. Use "
|
||||
"django.db.models.aggregates.BitOr instead.",
|
||||
category=RemovedInDjango70Warning,
|
||||
stacklevel=2,
|
||||
)
|
||||
super().__init__(expression, **extra)
|
||||
|
||||
|
||||
class BitXor(_BitXor):
|
||||
def __init__(self, expression, **extra):
|
||||
warnings.warn(
|
||||
"The PostgreSQL-specific BitXor function is deprecated. Use "
|
||||
"django.db.models.aggregates.BitXor instead.",
|
||||
category=RemovedInDjango70Warning,
|
||||
stacklevel=2,
|
||||
)
|
||||
super().__init__(expression, **extra)
|
||||
|
||||
|
||||
class BoolAnd(Aggregate):
|
||||
function = "BOOL_AND"
|
||||
output_field = BooleanField()
|
||||
|
||||
|
||||
class BoolOr(Aggregate):
|
||||
function = "BOOL_OR"
|
||||
output_field = BooleanField()
|
||||
|
||||
|
||||
class JSONBAgg(Aggregate):
|
||||
function = "JSONB_AGG"
|
||||
allow_distinct = True
|
||||
allow_order_by = True
|
||||
output_field = JSONField()
|
||||
|
||||
|
||||
# RemovedInDjango70Warning: When the deprecation ends, remove completely.
|
||||
class StringAgg(_StringAgg):
|
||||
|
||||
def __init__(self, expression, delimiter, **extra):
|
||||
if isinstance(delimiter, str):
|
||||
warnings.warn(
|
||||
"delimiter: str will be resolved as a field reference instead "
|
||||
"of a string literal on Django 7.0. Pass "
|
||||
f"`delimiter=Value({delimiter!r})` to preserve the previous behavior.",
|
||||
category=RemovedInDjango70Warning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
delimiter = Value(delimiter)
|
||||
|
||||
warnings.warn(
|
||||
"The PostgreSQL specific StringAgg function is deprecated. Use "
|
||||
"django.db.models.aggregates.StringAgg instead.",
|
||||
category=RemovedInDjango70Warning,
|
||||
stacklevel=2,
|
||||
)
|
||||
|
||||
super().__init__(expression, delimiter, **extra)
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
# RemovedInDjango70Warning: When the deprecation ends, remove completely.
|
||||
import warnings
|
||||
|
||||
from django.utils.deprecation import RemovedInDjango70Warning
|
||||
|
||||
|
||||
# RemovedInDjango70Warning.
|
||||
class OrderableAggMixin:
|
||||
allow_order_by = True
|
||||
|
||||
def __init_subclass__(cls, /, *args, **kwargs):
|
||||
warnings.warn(
|
||||
"OrderableAggMixin is deprecated. Use Aggregate and allow_order_by "
|
||||
"instead.",
|
||||
category=RemovedInDjango70Warning,
|
||||
stacklevel=1,
|
||||
)
|
||||
super().__init_subclass__(*args, **kwargs)
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
from django.db.models import Aggregate, FloatField, IntegerField
|
||||
|
||||
__all__ = [
|
||||
"CovarPop",
|
||||
"Corr",
|
||||
"RegrAvgX",
|
||||
"RegrAvgY",
|
||||
"RegrCount",
|
||||
"RegrIntercept",
|
||||
"RegrR2",
|
||||
"RegrSlope",
|
||||
"RegrSXX",
|
||||
"RegrSXY",
|
||||
"RegrSYY",
|
||||
"StatAggregate",
|
||||
]
|
||||
|
||||
|
||||
class StatAggregate(Aggregate):
|
||||
output_field = FloatField()
|
||||
|
||||
def __init__(self, y, x, output_field=None, filter=None, default=None):
|
||||
if not x or not y:
|
||||
raise ValueError("Both y and x must be provided.")
|
||||
super().__init__(
|
||||
y, x, output_field=output_field, filter=filter, default=default
|
||||
)
|
||||
|
||||
|
||||
class Corr(StatAggregate):
|
||||
function = "CORR"
|
||||
|
||||
|
||||
class CovarPop(StatAggregate):
|
||||
def __init__(self, y, x, sample=False, filter=None, default=None):
|
||||
self.function = "COVAR_SAMP" if sample else "COVAR_POP"
|
||||
super().__init__(y, x, filter=filter, default=default)
|
||||
|
||||
|
||||
class RegrAvgX(StatAggregate):
|
||||
function = "REGR_AVGX"
|
||||
|
||||
|
||||
class RegrAvgY(StatAggregate):
|
||||
function = "REGR_AVGY"
|
||||
|
||||
|
||||
class RegrCount(StatAggregate):
|
||||
function = "REGR_COUNT"
|
||||
output_field = IntegerField()
|
||||
empty_result_set_value = 0
|
||||
|
||||
|
||||
class RegrIntercept(StatAggregate):
|
||||
function = "REGR_INTERCEPT"
|
||||
|
||||
|
||||
class RegrR2(StatAggregate):
|
||||
function = "REGR_R2"
|
||||
|
||||
|
||||
class RegrSlope(StatAggregate):
|
||||
function = "REGR_SLOPE"
|
||||
|
||||
|
||||
class RegrSXX(StatAggregate):
|
||||
function = "REGR_SXX"
|
||||
|
||||
|
||||
class RegrSXY(StatAggregate):
|
||||
function = "REGR_SXY"
|
||||
|
||||
|
||||
class RegrSYY(StatAggregate):
|
||||
function = "REGR_SYY"
|
||||
Reference in New Issue
Block a user