diff --git a/datafaker/interactive/generators.py b/datafaker/interactive/generators.py index c65cc4c..e2d4460 100644 --- a/datafaker/interactive/generators.py +++ b/datafaker/interactive/generators.py @@ -790,7 +790,7 @@ def _proposers_valid(self) -> bool: def _get_proposer_proposals(self) -> list[Proposer]: """ - Get a list of acceptable proposers, sorted by decreasing fit to the actual data. + Get a list of acceptable proposers, sorted by name. The cached list from the most recent 'propose'/'propose all' is reused if still valid for the current table/columns, so that 'set @@ -801,7 +801,7 @@ def _get_proposer_proposals(self) -> list[Proposer]: props = everything_factory(self.config, self.metadata).get_proposers( columns, self.sync_engine ) - sorted_props = sorted(props, key=lambda g: g.fit(9999)) + sorted_props = sorted(props, key=lambda g: g.name()) self.proposers = sorted_props self.proposers_valid_columns = ( self.table_index, diff --git a/datafaker/proposers/base.py b/datafaker/proposers/base.py index 6b456ca..b778c9b 100644 --- a/datafaker/proposers/base.py +++ b/datafaker/proposers/base.py @@ -139,15 +139,6 @@ def actual_kwargs(self) -> dict[str, Any]: def generate_data(self, count: int) -> list[Any]: """Generate ``count`` random data points for this column.""" - def fit(self, default: float = -1) -> float: - """ - Return a value representing how well the distribution fits the real source data. - - 0.0 means "perfectly". - Returns default if no fitness has been defined. - """ - return default - def guarantees_fresh_uniqueness(self) -> bool: """ Whether this proposer is structurally guaranteed never to collide. @@ -301,13 +292,6 @@ def get_proposers( """Get the proposers appropriate to these columns.""" -def fit_from_buckets(xs: Sequence[NumericType], ys: Sequence[NumericType]) -> float: - """Calculate the fit by comparing a pair of lists of buckets.""" - sum_diff_squared = sum(map(lambda t, a: (t - a) * (t - a), xs, ys)) - count = len(ys) - return sum_diff_squared / (count * count) - - class ForeignKeyRelationship: """How a table is related.""" @@ -406,51 +390,12 @@ class Buckets: # pylint: disable=too-many-arguments too-many-positional-arguments def __init__( self, - engine: Engine, - table: Table | Join, - column: Any, mean: float, stddev: float, - count: int, - anchor_relation: RelatedColumn | None = None, ): """Initialise a Buckets object.""" self.mean = mean self.stddev = stddev - query = self._get_bucket_query(table, column, anchor_relation) - with engine.connect() as connection: - raw_buckets = connection.execute(query.group_by("b")) - self.buckets: Sequence[int] = [0] * 10 - for rb in raw_buckets: - try: - x = float(rb.b) - if x.is_integer(): - bucket = min(9, max(0, int(x) + 1)) - self.buckets[bucket] += rb.f / count - except TypeError: - # We get a type error if there are no rows returned at all - # because rb.b is None in this case. - # We could just test for None explicitly, but this way - # catches errors if SQLAlchemy returns something that - # isn't a number for some other unknown reason. - pass - - def _get_bucket_query( - self, - table: Table | Join, - column: Any, - anchor_relation: RelatedColumn | None = None, - ) -> Any: - """Make the query for half-sd buckets.""" - bottom = self.mean - 2 * self.stddev - width = self.stddev / 2 - query = select( - func.count(column).label("f"), # pylint: disable=not-callable - ((func.floor(column) - bottom) / width).label("b"), - ).select_from(table) - if anchor_relation is not None: - query = anchor_relation.add_join_to_query(query) - return query @classmethod def make_buckets( @@ -488,33 +433,14 @@ def make_buckets( return None try: buckets = cls( - engine, - table, - column, result.mean, result.stddev, - getattr(result, "count"), - anchor_relation, ) except DatabaseError as exc: logger.debug("Failed to instantiate Buckets object: %s", exc) return None return buckets - def fit_from_counts(self, bucket_counts: Sequence[float]) -> float: - """Figure out the fit from bucket counts from the generator distribution.""" - return fit_from_buckets(self.buckets, bucket_counts) - - def fit_from_values(self, values: list[float]) -> float: - """Figure out the fit from samples from the generator distribution.""" - buckets = [0] * 10 - x = self.mean - 2 * self.stddev - w = self.stddev / 2 - for v in values: - b = min(9, max(0, int((v - x) / w))) - buckets[b] += 1 - return self.fit_from_counts(buckets) - class MultiProposerFactory(ProposerFactory): """A composite factory.""" diff --git a/datafaker/proposers/choice.py b/datafaker/proposers/choice.py index 694231a..007cfe6 100644 --- a/datafaker/proposers/choice.py +++ b/datafaker/proposers/choice.py @@ -1,20 +1,12 @@ """Generator factories for making generators for choices of values.""" import decimal -import math -import typing -from abc import abstractmethod from typing import Any, Sequence, Union from sqlalchemy import Column, CursorResult, Engine, desc, func, select from datafaker.dialects import random_sample -from datafaker.proposers.base import ( - Proposer, - ProposerFactory, - dist_gen, - fit_from_buckets, -) +from datafaker.proposers.base import Proposer, ProposerFactory, dist_gen NumericType = Union[int, float] @@ -23,28 +15,6 @@ MAXIMUM_CHOICES = 500 -def zipf_distribution(total: int, bins: int) -> typing.Generator[int, None, None]: - """ - Get a zipf distribution for a certain number of items. - - :param total: The total number of items to be distributed. - :param bins: The total number of bins to distribute the items into. - :return: A generator of the number of items in each bin, from the - largest to the smallest. - """ - basic_dist = list(map(lambda n: 1 / n, range(1, bins + 1))) - bd_remaining = sum(basic_dist) - for b in basic_dist: - # yield b/bd_remaining of the `total` remaining - if bd_remaining == 0: - yield 0 - else: - x = math.floor(0.5 + total * b / bd_remaining) - bd_remaining -= x * bd_remaining / total - total -= x - yield x - - def _choice_stmt( # pylint: disable=R0913,R0917 column: Column, store_counts: bool, @@ -100,7 +70,6 @@ def __init__( self, column: Column, values: list[Any], - counts: list[int], sample_count: int | None = None, suppress_count: int = 0, dialect: Any = None, @@ -109,8 +78,6 @@ def __init__( super().__init__() self.column = column self.values = values - estimated_counts = self.get_estimated_counts(counts) - self._fit = fit_from_buckets(counts, estimated_counts) extra_comment = " and their counts" if self.STORE_COUNTS else "" stmt = _choice_stmt( @@ -152,10 +119,6 @@ def __init__( ) self._annotation = "sampled and suppressed" - @abstractmethod - def get_estimated_counts(self, counts: list[int]) -> list[int]: - """Get the counts that we would expect if this distribution was the correct one.""" - def nominal_kwargs(self) -> dict[str, Any]: """Get the arguments to be entered into ``config.yaml``.""" return { @@ -186,18 +149,10 @@ def custom_queries(self) -> dict[str, dict[str, Any]]: }, } - def fit(self, default: float = -1) -> float: - """Get this generator's fit against the real data.""" - return default if self._fit is None else self._fit - class ZipfChoiceProposer(ChoiceProposer): """Generator producing items in a Zipf distribution.""" - def get_estimated_counts(self, counts: list[int]) -> list[int]: - """Get the counts that we would expect if this distribution was the correct one.""" - return list(zipf_distribution(sum(counts), len(counts))) - def function_name(self) -> str: """Get the name of the generator function to call.""" return "dist_gen.zipf_choice" @@ -210,28 +165,9 @@ def generate_data(self, count: int) -> list[float]: ] -def uniform_distribution(total: int, bins: int) -> typing.Generator[int, None, None]: - """ - Construct a distribution putting ``total`` items uniformly into ``bins`` bins. - - If they don't fit exactly evenly, the earlier bins will have one more - item than the later bins so the total is as required. - """ - p = total // bins - n = total % bins - for _ in range(0, n): - yield p + 1 - for _ in range(n, bins): - yield p - - class UniformChoiceProposer(ChoiceProposer): """A proposer producing values, each roughly as frequently as each other.""" - def get_estimated_counts(self, counts: list[int]) -> list[int]: - """Get the counts that we would expect if this distribution was the correct one.""" - return list(uniform_distribution(sum(counts), len(counts))) - def function_name(self) -> str: """Get the name of the generator function to call.""" return "dist_gen.choice" @@ -347,19 +283,16 @@ def get_proposers( # pylint: disable=too-many-locals ZipfChoiceProposer( column, vg.values, - vg.counts, dialect=dialect, ), UniformChoiceProposer( column, vg.values, - vg.counts, dialect=dialect, ), WeightedChoiceProposer( column, vg.cvs, - vg.counts, dialect=dialect, ), ] @@ -368,21 +301,18 @@ def get_proposers( # pylint: disable=too-many-locals ZipfChoiceProposer( column, vg.values_not_suppressed, - vg.counts_not_suppressed, suppress_count=self.SUPPRESS_COUNT, dialect=dialect, ), UniformChoiceProposer( column, vg.values_not_suppressed, - vg.counts_not_suppressed, suppress_count=self.SUPPRESS_COUNT, dialect=dialect, ), WeightedChoiceProposer( column=column, values=vg.cvs_not_suppressed, - counts=vg.counts_not_suppressed, suppress_count=self.SUPPRESS_COUNT, dialect=dialect, ), @@ -406,21 +336,18 @@ def get_proposers( # pylint: disable=too-many-locals ZipfChoiceProposer( column, vg.values, - vg.counts, sample_count=self.SAMPLE_COUNT, dialect=dialect, ), UniformChoiceProposer( column, vg.values, - vg.counts, sample_count=self.SAMPLE_COUNT, dialect=dialect, ), WeightedChoiceProposer( column, vg.cvs, - vg.counts, sample_count=self.SAMPLE_COUNT, dialect=dialect, ), @@ -430,7 +357,6 @@ def get_proposers( # pylint: disable=too-many-locals ZipfChoiceProposer( column, vg.values_not_suppressed, - vg.counts_not_suppressed, sample_count=self.SAMPLE_COUNT, suppress_count=self.SUPPRESS_COUNT, dialect=dialect, @@ -438,7 +364,6 @@ def get_proposers( # pylint: disable=too-many-locals UniformChoiceProposer( column, vg.values_not_suppressed, - vg.counts_not_suppressed, sample_count=self.SAMPLE_COUNT, suppress_count=self.SUPPRESS_COUNT, dialect=dialect, @@ -446,7 +371,6 @@ def get_proposers( # pylint: disable=too-many-locals WeightedChoiceProposer( column=column, values=vg.cvs_not_suppressed, - counts=vg.counts_not_suppressed, sample_count=self.SAMPLE_COUNT, suppress_count=self.SUPPRESS_COUNT, dialect=dialect, diff --git a/datafaker/proposers/continuous.py b/datafaker/proposers/continuous.py index d72f640..20ebe91 100644 --- a/datafaker/proposers/continuous.py +++ b/datafaker/proposers/continuous.py @@ -29,7 +29,6 @@ from datafaker.dialects import IsNotNull, LogNatural, NullIf, StdDev, random_sample from datafaker.proposers.base import ( Buckets, - NumericType, Proposer, ProposerFactory, dist_gen, @@ -41,8 +40,6 @@ class ContinuousDistributionProposer(Proposer): """Base class for generators producing continuous distributions.""" - expected_buckets: Sequence[NumericType] = [] - def __init__( self, table: Table, @@ -100,29 +97,10 @@ def select_aggregate_clauses(self) -> dict[str, dict[str, str]]: }, } - def fit(self, default: float = -1) -> float: - """Get this generator's fit against the real data.""" - if self.buckets is None: - return default - return self.buckets.fit_from_counts(self.expected_buckets) - class GaussianProposer(ContinuousDistributionProposer): """Generator producing numbers in a Gaussian (normal) distribution.""" - expected_buckets = [ - 0.0227, - 0.0441, - 0.0918, - 0.1499, - 0.1915, - 0.1915, - 0.1499, - 0.0918, - 0.0441, - 0.0227, - ] - def function_name(self) -> str: """Get the name of the generator function to call.""" return "dist_gen.normal" @@ -138,19 +116,6 @@ def generate_data(self, count: int) -> list[Any]: class UniformProposer(ContinuousDistributionProposer): """Generator producing numbers in a uniform distribution.""" - expected_buckets = [ - 0, - 0.06698, - 0.14434, - 0.14434, - 0.14434, - 0.14434, - 0.14434, - 0.14434, - 0.06698, - 0, - ] - def function_name(self) -> str: """Get the name of the generator function to call.""" return "dist_gen.uniform_ms" @@ -199,31 +164,11 @@ def get_proposers( class LogNormalProposer(Proposer): """Generator producing numbers in a log-normal distribution.""" - # R: - # > xs<-seq(-2,2,0.5)*sqrt((exp(1)-1)*exp(1))+exp(0.5) - # > ys <- plnorm(xs) - # > c(ys, 1) - c(0,ys) - # [1] 0.00000000 0.00000000 0.00000000 0.28589471 0.40556775 0.15086088 - # [7] 0.06716451 0.03428958 0.01924848 0.03697409 - expected_buckets = [ - 0, - 0, - 0, - 0.28589471, - 0.40556775, - 0.15086088, - 0.06716451, - 0.03428958, - 0.01924848, - 0.03697409, - ] - # pylint: disable=too-many-arguments too-many-positional-arguments def __init__( self, table: Table, column: Column, - buckets: Buckets, logmean: float, logstddev: float, dialect: Dialect, @@ -232,7 +177,6 @@ def __init__( super().__init__() self.table = table self.column = column - self.buckets = buckets self.logmean = logmean self.logstddev = logstddev self._dialect = dialect @@ -290,17 +234,11 @@ def select_aggregate_clauses(self) -> dict[str, dict[str, str]]: }, } - def fit(self, default: float = -1) -> float: - """Get this generator's fit against the real data.""" - if self.buckets is None: - return default - return self.buckets.fit_from_counts(self.expected_buckets) - class ContinuousLogDistributionProposerFactory(ContinuousDistributionProposerFactory): """All generators that want an average and standard deviation of log data.""" - def _get_generators_from_buckets( + def _get_generators_from_buckets( # pylint: disable=unused-argument self, engine: Engine, src_table: Table, @@ -308,12 +246,12 @@ def _get_generators_from_buckets( buckets: Buckets, ) -> Sequence[Proposer]: col = case( - (column > 0, func.log(column)), + (column > 0, LogNatural(column)), else_=null(), ) stmt = select( func.avg(col).label("logmean"), - func.stddev_samp(col).label("logstddev"), + StdDev(col).label("logstddev"), ).select_from(src_table) with engine.connect() as connection: result = connection.execute(stmt).first() @@ -323,7 +261,6 @@ def _get_generators_from_buckets( LogNormalProposer( src_table, column, - buckets, float(result.logmean), float(result.logstddev), dialect=engine.dialect, @@ -395,10 +332,6 @@ def generate_data(self, count: int) -> list[Any]: for _ in range(count) ] - def fit(self, default: float = -1) -> float: - """Get this generator's fit against the real data.""" - return default - class MultivariateNormalGeneratorFactoryBase(ProposerFactory): """Generator factory that makes distributions and maybe partitions.""" diff --git a/datafaker/proposers/extract.py b/datafaker/proposers/extract.py index f4fe9d3..3dbdb7d 100644 --- a/datafaker/proposers/extract.py +++ b/datafaker/proposers/extract.py @@ -60,11 +60,6 @@ def custom_queries(self) -> dict[str, dict[str, Any]]: """Return that no data is required from the database.""" return {} - def fit(self, default: float = -1) -> float: - """Get this generator's fit against the real data.""" - # What should the fit really be? - return 0.0 - def get_based_on_data(self, count: int) -> list[datetime.datetime]: """Get the data from the based-on column in the source data.""" with self._engine.connect() as conn: diff --git a/datafaker/proposers/intervals.py b/datafaker/proposers/intervals.py index ef17f46..de42947 100644 --- a/datafaker/proposers/intervals.py +++ b/datafaker/proposers/intervals.py @@ -9,7 +9,6 @@ from datafaker.dialects import SecondsDifference, StdDev, random_sample from datafaker.proposers.base import ( - Buckets, ForeignKeyRelationship, Proposer, ProposerFactory, @@ -184,7 +183,6 @@ def __init__( column: Column, anchor_related: RelatedColumn, engine: Engine, - buckets: Buckets | None = None, ): """ Initialise a date after proposer. @@ -196,7 +194,6 @@ def __init__( :param anchor: The anchor column, which must be in the same table as column or a related table. :param engine: The source database. - :param buckets: The buckets for the intervals in the source database. """ super().__init__() self._sd = sd @@ -205,13 +202,6 @@ def __init__( self._column = column self._engine = engine self._provider = AnchoredProvider(metadata=metadata) - if buckets is None: - self._fit = None - return - intervals = self.generate_intervals(400) - self._fit = buckets.fit_from_values( - [(b - coerce_to_datetime(a, b)).total_seconds() for (a, b) in intervals] - ) @classmethod def get_query( @@ -361,10 +351,6 @@ def custom_queries(self) -> dict[str, dict[str, Any]]: } } - def fit(self, default: float = -1) -> float: - """Get this generator's fit against the real data.""" - return default if self._fit is None else self._fit - def generate_data(self, count: int) -> list[datetime.datetime]: """Generate ``count`` random data points for this column.""" return [b for (_, b) in self.generate_intervals(count)] @@ -416,12 +402,6 @@ def _make_date_after_proposers( result = connection.execute(query).first() if result is None or result.sd is None: return [] - buckets = Buckets.make_buckets( - engine, - column.table, - SecondsDifference(column, anchor_related.target), - anchor_related, - ) return [ DateAfterProposer( self._metadata, @@ -430,7 +410,6 @@ def _make_date_after_proposers( column, anchor_related, engine=engine, - buckets=buckets, ) ] @@ -537,10 +516,6 @@ def custom_queries(self) -> dict[str, dict[str, Any]]: """No source data required.""" return {} - def fit(self, default: float = -1) -> float: - """Get this generator's fit against the real data.""" - return default - def generate_data(self, count: int) -> list[Any]: """Generate ``count`` random data points for this column.""" anchor = self._anchor_related.target diff --git a/datafaker/proposers/mimesis.py b/datafaker/proposers/mimesis.py index dbb9282..ca6e203 100644 --- a/datafaker/proposers/mimesis.py +++ b/datafaker/proposers/mimesis.py @@ -6,11 +6,9 @@ import mimesis import mimesis.locales from sqlalchemy import Column, Engine, cast, extract, func, select -from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.types import Date, DateTime, Integer, Numeric, String, Time from datafaker.proposers.base import ( - Buckets, Proposer, ProposerError, ProposerFactory, @@ -68,30 +66,6 @@ def generate_data(self, count: int) -> list[Any]: class MimesisProposer(MimesisProposerBase): """A generator using Mimesis.""" - def __init__( - self, - function_name: str, - value_fn: Callable[[Any], float] | None = None, - buckets: Buckets | None = None, - ): - """ - Initialise a generator using Mimesis. - - :param function_name: is relative to 'generic', for example 'person.name'. - :param value_fn: Function to convert generator output to floats, if needed. The values - thus produced are compared against the buckets to estimate the fit. - :param buckets: The distribution of string lengths in the real data. If this is None - then the fit method will return None. - """ - super().__init__(function_name) - if buckets is None: - self._fit = None - return - samples = self.generate_data(400) - if value_fn: - samples = [value_fn(s) for s in samples] - self._fit = buckets.fit_from_values(samples) - def function_name(self) -> str: """Get the name of the generator function to call.""" return self._name @@ -104,10 +78,6 @@ def actual_kwargs(self) -> dict[str, Any]: """Get the kwargs (summary statistics) this generator was instantiated with.""" return {} - def fit(self, default: float = -1) -> float: - """Get this generator's fit against the real data.""" - return default if self._fit is None else self._fit - class MimesisGeneratorTruncated(MimesisProposer): """A string generator using Mimesis that must fit within a certain number of characters.""" @@ -116,12 +86,10 @@ def __init__( self, function_name: str, length: int, - value_fn: Callable[[Any], float] | None = None, - buckets: Buckets | None = None, ): """Initialise a MimesisGeneratorTruncated.""" self._length = length - super().__init__(function_name, value_fn, buckets) + super().__init__(function_name) def function_name(self) -> str: """Get the name of the generator function to call.""" @@ -320,32 +288,10 @@ def get_proposers( column_type = get_column_type(column) if not isinstance(column_type, String): return [] - try: - buckets = Buckets.make_buckets( - engine, - column.table, - func.length(column), - ) - fitness_fn = len - except SQLAlchemyError: - # Some column types that appear to be strings (such as enums) - # cannot have their lengths measured. In this case we cannot - # detect fitness using lengths. - buckets = None - fitness_fn = None length = column_type.length if length: - return self._get_generators_with( - MimesisGeneratorTruncated, - length=length, - value_fn=fitness_fn, - buckets=buckets, - ) - return self._get_generators_with( - MimesisProposer, - value_fn=fitness_fn, - buckets=buckets, - ) + return self._get_generators_with(MimesisGeneratorTruncated, length=length) + return self._get_generators_with(MimesisProposer) class MimesisFloatProposerFactory(ProposerFactory): diff --git a/datafaker/proposers/partitioned.py b/datafaker/proposers/partitioned.py index 6f8bc66..53feb84 100644 --- a/datafaker/proposers/partitioned.py +++ b/datafaker/proposers/partitioned.py @@ -340,10 +340,6 @@ def generate_data(self, count: int) -> list[Any]: kwargs = self.actual_kwargs() return [dist_gen.alternatives(**kwargs) for _ in range(count)] - def fit(self, default: float = -1) -> float: - """Get this generator's fit against the real data.""" - return default - def is_numeric(col: Column) -> bool: """Test if this column stores a numeric value.""" diff --git a/tests/test_evaluators_proposal_ranking.py b/tests/test_evaluators_proposal_ranking.py index 64c033f..fb93a27 100644 --- a/tests/test_evaluators_proposal_ranking.py +++ b/tests/test_evaluators_proposal_ranking.py @@ -1,4 +1,5 @@ """Unit tests for datafaker.evaluators.proposal_ranking.""" + from typing import Any from sqlalchemy import Column, MetaData, Table, Text @@ -230,7 +231,7 @@ def test_keyword_boost_can_flip_the_recommendation(self) -> None: def test_choice_proposer_penalized_by_resampling_on_unique_column(self) -> None: """ChoiceProposer's score is discounted by real_uniqueness x copy_fraction.""" table = Table("t", MetaData(), Column("c", Text())) - choice_proposer = UniformChoiceProposer(table.c.c, ["a", "b"], [1, 1]) + choice_proposer = UniformChoiceProposer(table.c.c, ["a", "b"]) results = [ make_result(overall_score=0.0, copy_fraction=1.0, proposer=choice_proposer), make_result(overall_score=0.5, copy_fraction=0.0), @@ -311,7 +312,7 @@ def test_combined_score_is_clamped_to_one(self) -> None: def test_weak_recommendation_warning_when_best_fit_was_suppressed(self) -> None: """A heavily-discounted best-fit candidate triggers the fallback warning.""" table = Table("t", MetaData(), Column("c", Text())) - choice_proposer = UniformChoiceProposer(table.c.c, ["a", "b"], [1, 1]) + choice_proposer = UniformChoiceProposer(table.c.c, ["a", "b"]) results = [ # Fits almost perfectly but is a resampler on a near-unique column: # gets discounted to (near) zero. diff --git a/tests/test_functional_mssql.py b/tests/test_functional_mssql.py index 8919186..b22a765 100644 --- a/tests/test_functional_mssql.py +++ b/tests/test_functional_mssql.py @@ -12,6 +12,7 @@ docker compose up -d mssql # wait ~30 s for SQL Server to start """ + import asyncio import os from tempfile import mkstemp @@ -50,7 +51,7 @@ def setUp(self) -> None: super().setUp() # Write orm.yaml so generate_data() has the file it expects. - (self.orm_fd, self.orm_file_path) = mkstemp(".yaml", "orm_", text=True) + self.orm_fd, self.orm_file_path = mkstemp(".yaml", "orm_", text=True) with os.fdopen(self.orm_fd, "w", encoding="utf-8") as fh: fh.write( make_tables_file( @@ -126,7 +127,6 @@ def test_dialect_rand(self) -> None: proposer = ZipfChoiceProposer( column=table.c.name, values=["Blender", "Gibbs"], - counts=[5, 5], sample_count=2, dialect=dialect, ) diff --git a/tests/test_generators_dialect.py b/tests/test_generators_dialect.py index 99261c1..b946049 100644 --- a/tests/test_generators_dialect.py +++ b/tests/test_generators_dialect.py @@ -1,4 +1,5 @@ """Tests for dialect-correct SQL in generator classes.""" + # pylint: disable=protected-access import unittest import unittest.mock @@ -121,9 +122,9 @@ def capture_execute(stmt, *args, **kwargs): self.assertEqual(len(executed_stmts), 1) compiled = str( executed_stmts[0].compile( - dialect=mssql.dialect() - if dialect_name == "mssql" - else postgresql.dialect(), + dialect=( + mssql.dialect() if dialect_name == "mssql" else postgresql.dialect() + ), compile_kwargs={"literal_binds": True}, ) ) @@ -154,7 +155,6 @@ def _make_gen(self, dialect, sample_count=None, suppress_count=0): return ZipfChoiceProposer( column=table.c.gender, values=["M", "F"], - counts=[70, 30], sample_count=sample_count, suppress_count=suppress_count, dialect=dialect, @@ -544,9 +544,7 @@ def test_lognormal_postgresql_uses_stddev(self) -> None: """LogNormalProposer.select_aggregate_clauses uses STDDEV on PostgreSQL.""" tbl, col = self._make_table() - proposer = LogNormalProposer( - tbl, col, MagicMock(), 1.0, 0.5, dialect=postgresql.dialect() - ) + proposer = LogNormalProposer(tbl, col, 1.0, 0.5, dialect=postgresql.dialect()) clause = proposer.select_aggregate_clauses()["logstddev__age"]["clause"] self.assert_str_in("STDDEV", clause.upper()) @@ -554,9 +552,7 @@ def test_lognormal_mssql_uses_stdev(self) -> None: """LogNormalProposer.select_aggregate_clauses uses STDEV on MSSQL.""" tbl, col = self._make_table() - proposer = LogNormalProposer( - tbl, col, MagicMock(), 1.0, 0.5, dialect=mssql.dialect() - ) + proposer = LogNormalProposer(tbl, col, 1.0, 0.5, dialect=mssql.dialect()) clause = proposer.select_aggregate_clauses()["logstddev__age"]["clause"] self.assert_str_in("STDEV", clause.upper()) self.assert_str_not_in("STDDEV", clause.upper())