aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--generalresearch/incite/base.py5
-rw-r--r--generalresearch/models/cint/survey.py14
-rw-r--r--generalresearch/models/dynata/survey.py6
-rw-r--r--generalresearch/models/dynata/task_collection.py2
-rw-r--r--generalresearch/models/prodege/task_collection.py6
-rw-r--r--generalresearch/models/thl/contest/__init__.py7
-rw-r--r--generalresearch/models/thl/contest/contest_entry.py1
-rw-r--r--generalresearch/models/thl/leaderboard.py17
-rw-r--r--generalresearch/models/thl/survey/penalty.py5
-rw-r--r--generalresearch/utils/copying_cache.py2
-rw-r--r--pyproject.toml4
11 files changed, 36 insertions, 33 deletions
diff --git a/generalresearch/incite/base.py b/generalresearch/incite/base.py
index 795aad9..54d1565 100644
--- a/generalresearch/incite/base.py
+++ b/generalresearch/incite/base.py
@@ -7,7 +7,7 @@ import re
import shutil
import subprocess
import warnings
-from concurrent.futures import Future
+from collections.abc import Callable, Sequence
from datetime import datetime, timedelta, timezone
from os import R_OK, access, listdir
from os.path import isdir
@@ -17,12 +17,9 @@ from sys import platform
from typing import (
TYPE_CHECKING,
Any,
- Callable,
- Sequence,
)
from uuid import uuid4
-import dask
import dask.dataframe as dd
import pandas as pd
import pyarrow.parquet as pq
diff --git a/generalresearch/models/cint/survey.py b/generalresearch/models/cint/survey.py
index 56384e3..21bc21a 100644
--- a/generalresearch/models/cint/survey.py
+++ b/generalresearch/models/cint/survey.py
@@ -4,7 +4,7 @@ import json
import logging
from datetime import datetime, timezone
from decimal import Decimal
-from typing import Any, Literal, Type
+from typing import Annotated, Any, Literal
from more_itertools import flatten
from pydantic import (
@@ -15,7 +15,7 @@ from pydantic import (
computed_field,
model_validator,
)
-from typing_extensions import Annotated, Self
+from typing_extensions import Self
from generalresearch.locales import Localelator
from generalresearch.models import Source, TaskCalculationType
@@ -73,9 +73,9 @@ class CintQuota(BaseModel):
@model_validator(mode="after")
def validate_condition_len(self) -> Self:
if self.quota_type == "total":
- assert (
- self.condition_hashes is None
- ), "total quota should not have conditions"
+ assert self.condition_hashes is None, (
+ "total quota should not have conditions"
+ )
elif self.quota_type == "client":
assert len(self.condition_hashes) > 0, "quota must have conditions"
return self
@@ -291,7 +291,7 @@ class CintSurvey(MarketplaceTask):
return data
@property
- def condition_model(self) -> Type[MarketplaceCondition]:
+ def condition_model(self) -> type[MarketplaceCondition]:
return CintCondition
@property
@@ -417,7 +417,7 @@ class CintSurvey(MarketplaceTask):
return d
@classmethod
- def from_mysql(cls, d: Dict[str, Any]) -> Self:
+ def from_mysql(cls, d: dict[str, Any]) -> Self:
d["created_at"] = d["created_at"].replace(tzinfo=timezone.utc)
d["last_updated"] = d["last_updated"].replace(tzinfo=timezone.utc)
d["qualifications"] = json.loads(d["qualifications"])
diff --git a/generalresearch/models/dynata/survey.py b/generalresearch/models/dynata/survey.py
index 0e1b3e5..e88491d 100644
--- a/generalresearch/models/dynata/survey.py
+++ b/generalresearch/models/dynata/survey.py
@@ -5,7 +5,7 @@ import logging
from datetime import timezone
from decimal import Decimal
from functools import cached_property
-from typing import Any, Literal, Type
+from typing import Any, Literal
from more_itertools import flatten
from pydantic import (
@@ -500,7 +500,7 @@ class DynataSurvey(MarketplaceTask):
return res
@property
- def condition_model(self) -> Type[MarketplaceCondition]:
+ def condition_model(self) -> type[MarketplaceCondition]:
return DynataCondition
@property
@@ -551,7 +551,7 @@ class DynataSurvey(MarketplaceTask):
return d
@classmethod
- def from_db(cls, d: Dict[str, Any]) -> Self:
+ def from_db(cls, d: dict[str, Any]) -> Self:
d["created"] = d["created"].replace(tzinfo=timezone.utc)
d["last_updated"] = d["last_updated"].replace(tzinfo=timezone.utc)
d["filters"] = json.loads(d["filters"])
diff --git a/generalresearch/models/dynata/task_collection.py b/generalresearch/models/dynata/task_collection.py
index 71cf3db..2b82bfd 100644
--- a/generalresearch/models/dynata/task_collection.py
+++ b/generalresearch/models/dynata/task_collection.py
@@ -54,7 +54,7 @@ DynataTaskCollectionSchema = DataFrameSchema(
class DynataTaskCollection(TaskCollection):
- items: List[DynataSurvey]
+ items: list[DynataSurvey]
_schema = DynataTaskCollectionSchema
def to_row(self, s: DynataSurvey) -> dict[str, Any]:
diff --git a/generalresearch/models/prodege/task_collection.py b/generalresearch/models/prodege/task_collection.py
index 19e594f..4544050 100644
--- a/generalresearch/models/prodege/task_collection.py
+++ b/generalresearch/models/prodege/task_collection.py
@@ -1,4 +1,4 @@
-from typing import Any, Dict, List
+from typing import Any
import pandas as pd
from pandera.pandas import Check, Column, DataFrameSchema, Index
@@ -30,8 +30,8 @@ ProdegeTaskCollectionSchema = DataFrameSchema(
"conversion_rate": Column(float, Check.between(0, 1), nullable=True),
"created": Column(dtype=pd.DatetimeTZDtype(tz="UTC")),
"updated": Column(dtype=pd.DatetimeTZDtype(tz="UTC")),
- "used_question_ids": Column(List[str]),
- "all_hashes": Column(List[str]), # set >> list for column support
+ "used_question_ids": Column(list[str]),
+ "all_hashes": Column(list[str]), # set >> list for column support
"is_recontact": Column(bool),
# Not including here: entrance_url, max_clicks_settings, past_participation, include_psids, exclude_psids,
# quotas, source, conditions
diff --git a/generalresearch/models/thl/contest/__init__.py b/generalresearch/models/thl/contest/__init__.py
index 363c8c0..c02acbe 100644
--- a/generalresearch/models/thl/contest/__init__.py
+++ b/generalresearch/models/thl/contest/__init__.py
@@ -1,6 +1,7 @@
from __future__ import annotations
from datetime import datetime, timezone
+from typing import Any
from uuid import uuid4
from pydantic import (
@@ -86,9 +87,9 @@ class ContestPrize(BaseModel):
@model_validator(mode="after")
def validate_cash_value(self) -> Self:
if self.kind == ContestPrizeKind.CASH:
- assert (
- self.estimated_cash_value == self.cash_amount
- ), "if kind is CASH, cash_amount must equal estimated_cash_value"
+ assert self.estimated_cash_value == self.cash_amount, (
+ "if kind is CASH, cash_amount must equal estimated_cash_value"
+ )
return self
diff --git a/generalresearch/models/thl/contest/contest_entry.py b/generalresearch/models/thl/contest/contest_entry.py
index cddae14..2a9ecde 100644
--- a/generalresearch/models/thl/contest/contest_entry.py
+++ b/generalresearch/models/thl/contest/contest_entry.py
@@ -1,6 +1,7 @@
from __future__ import annotations
from datetime import datetime, timezone
+from typing import Any
from uuid import uuid4
from pydantic import (
diff --git a/generalresearch/models/thl/leaderboard.py b/generalresearch/models/thl/leaderboard.py
index 399a906..bc55034 100644
--- a/generalresearch/models/thl/leaderboard.py
+++ b/generalresearch/models/thl/leaderboard.py
@@ -6,6 +6,7 @@ from datetime import datetime, timedelta, timezone
from enum import Enum
from typing import Literal
from uuid import UUID, uuid3
+from zoneinfo import ZoneInfo
import pandas as pd
from pydantic import (
@@ -17,7 +18,6 @@ from pydantic import (
field_validator,
model_validator,
)
-from zoneinfo import ZoneInfo
from generalresearch.models.custom_types import AwareDatetimeISO, UUIDStr
from generalresearch.models.legacy.api_status import StatusResponse
@@ -78,14 +78,19 @@ class Leaderboard(BaseModel):
weekly, and monthly leaderboard.
"""
- id: UUIDStr = Field(
+ # Note: id and name get auto-generated by the model_validators, but the fields need
+ # to be optional with a default or the model can't be inited.
+ # todo: these should really be computed_fields instead
+ id: UUIDStr | None = Field(
description="Unique ID for this leaderboard",
examples=["845b0074ad533df580ebb9c80cc3bce1"],
+ default=None,
)
- name: str = Field(
+ name: str | None = Field(
description="Descriptive name for the leaderboard based on the board_code",
examples=["Number of Completes"],
+ default=None,
)
board_code: LeaderboardCode = Field(
@@ -266,9 +271,9 @@ class Leaderboard(BaseModel):
.to_pydatetime()
.replace(tzinfo=self.timezone)
)
- assert (
- period_start_local == self.period_start_local
- ), f"invalid period_start_local {self.period_start_local}. The period starts at {period_start_local}"
+ assert period_start_local == self.period_start_local, (
+ f"invalid period_start_local {self.period_start_local}. The period starts at {period_start_local}"
+ )
if self.period_end_local is not None:
assert self.period_end_local == period_end_local, "invalid period"
else:
diff --git a/generalresearch/models/thl/survey/penalty.py b/generalresearch/models/thl/survey/penalty.py
index e9515d4..0f544b8 100644
--- a/generalresearch/models/thl/survey/penalty.py
+++ b/generalresearch/models/thl/survey/penalty.py
@@ -2,10 +2,9 @@ from __future__ import annotations
import abc
from datetime import datetime, timezone
-from typing import Literal
+from typing import Annotated, Literal
from pydantic import BaseModel, ConfigDict, Field, TypeAdapter
-from typing_extensions import Annotated
from generalresearch.models import Source
from generalresearch.models.custom_types import (
@@ -59,7 +58,7 @@ class TeamSurveyPenalty(SurveyPenalty):
Penalty = Annotated[
- Union[BPSurveyPenalty, TeamSurveyPenalty],
+ BPSurveyPenalty | TeamSurveyPenalty,
Field(discriminator="kind"),
]
PenaltyListAdapter = TypeAdapter(list[Penalty])
diff --git a/generalresearch/utils/copying_cache.py b/generalresearch/utils/copying_cache.py
index ea13f69..a1cb37c 100644
--- a/generalresearch/utils/copying_cache.py
+++ b/generalresearch/utils/copying_cache.py
@@ -1,6 +1,6 @@
+from collections.abc import Callable
from copy import deepcopy
from functools import wraps
-from typing import Callable
def deepcopy_return(fn: Callable) -> Callable:
diff --git a/pyproject.toml b/pyproject.toml
index fd55201..e855d16 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,12 +4,12 @@ build-backend = "setuptools.build_meta"
[project]
name = "generalresearch"
-version = "3.4.2"
+version = "3.4.4"
description = "Python Utilities for General Research"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
- "fastapi",
+# "fastapi",
"Faker",
"PyMySQL",
"psycopg",