Skip to content

Commit 8f3604b

Browse files
author
Tim Band
committed
Cleaned docs build
1 parent c7799ab commit 8f3604b

6 files changed

Lines changed: 58 additions & 62 deletions

File tree

datafaker/create.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ def create_db_data_into(
130130
Populate the database.
131131
132132
:param sorted_tables: The table names to populate, sorted so that foreign
133-
keys' targets are populated before the foreign keys themselves.
133+
keys' targets are populated before the foreign keys themselves.
134134
:param table_generator_dict: A mapping of table names to the generators
135-
used to make data for them.
135+
used to make data for them.
136136
:param story_generator_list: A list of story generators to be run after the
137-
table generators on each pass.
137+
table generators on each pass.
138138
:param num_passes: Number of passes to perform.
139139
:param db_dsn: Connection string for the destination database.
140140
:param schema_name: Destination schema name.
@@ -196,7 +196,7 @@ def table_name(self) -> str | None:
196196
Get the name of the current table.
197197
198198
:return: The table name, or None if there are no more stories
199-
to process.
199+
to process.
200200
"""
201201
return self._table_name
202202

datafaker/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def load_metadata_config(
7878
7979
:param orm_file_name: The name of the file to load.
8080
:param config: The ``config.yaml`` file object. Ignored tables will be
81-
excluded from the output.
81+
excluded from the output.
8282
:return: A dict representing the ``orm.yaml`` file, with the tables
83-
the ``config`` says to ignore removed.
83+
the ``config`` says to ignore removed.
8484
"""
8585
with open(orm_file_name, encoding="utf-8") as orm_fh:
8686
meta_dict = yaml.load(orm_fh, yaml.Loader)

datafaker/make.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from datetime import datetime
77
from pathlib import Path
88
from types import TracebackType
9-
from typing import Any, Callable, Final, Mapping, Optional, Sequence, Tuple, Type
9+
from typing import Any, Callable, Final, Mapping, Optional, Sequence, Tuple, Type, Union
1010

1111
import pandas as pd
1212
import snsql
@@ -90,8 +90,8 @@ def make_column_choices(
9090
9191
:param table_config: The ``tables`` part of ``config.yaml``.
9292
:return: A list of ``ColumnChoice`` objects; that is, descriptions of
93-
functions and their arguments to call to reveal a list of columns that
94-
should have values generated for them.
93+
functions and their arguments to call to reveal a list of columns that
94+
should have values generated for them.
9595
"""
9696
return [
9797
ColumnChoice(
@@ -125,7 +125,7 @@ class TableGeneratorInfo:
125125
column_choices: list[ColumnChoice]
126126
rows_per_pass: int
127127
row_gens: list[RowGeneratorInfo] = field(default_factory=list)
128-
unique_constraints: Sequence[UniqueConstraint | _PrimaryConstraint] = field(
128+
unique_constraints: Sequence[Union[UniqueConstraint, _PrimaryConstraint]] = field(
129129
default_factory=list
130130
)
131131

@@ -286,7 +286,7 @@ def _integer_generator(column: Column) -> tuple[str, dict[str, str]]:
286286
287287
:param column: The column to get the generator for.
288288
:return: A pair consisting of the name of a generator and its
289-
arguments.
289+
arguments.
290290
"""
291291
if not column.primary_key:
292292
return ("generic.numeric.integer_number", {})
@@ -423,7 +423,7 @@ def _get_generator_and_arguments(column: Column) -> tuple[str | None, dict[str,
423423
Get the generator and its arguments from the column type.
424424
425425
:return: A tuple of a string representing the generator callable and a dict of
426-
keyword arguments to supply to it.
426+
keyword arguments to supply to it.
427427
"""
428428
generator_function = _get_generator_for_column(type(column.type))
429429

@@ -437,12 +437,10 @@ def _get_provider_for_column(column: Column) -> Tuple[list[str], str, dict[str,
437437
"""
438438
Get a default Mimesis provider and its arguments for a SQL column type.
439439
440-
Args:
441-
column: SQLAlchemy column object
440+
:param column: SQLAlchemy column object
442441
443-
Returns:
444-
Tuple[str, str, list[str]]: Tuple containing the variable names to assign to,
445-
generator function and any generator arguments.
442+
:return: Tuple[str, str, list[str]]: Tuple containing the variable names
443+
to assign to, generator function and any generator arguments.
446444
"""
447445
variable_names: list[str] = [column.name]
448446

@@ -589,19 +587,17 @@ def make_table_generators( # pylint: disable=too-many-locals
589587
The orm and vocabulary YAML files must already have been
590588
generated (by make-tables and make-vocab).
591589
592-
Args:
593-
metadata: database ORM
594-
config: Configuration to control the generator creation.
595-
orm_filename: "orm.yaml" file path so that the generator
596-
file can load the MetaData object
597-
config_filename: "config.yaml" file path so that the generator
598-
file can load the MetaData object
599-
src_stats_filename: A filename for where to read src stats from.
590+
:param metadata: database ORM
591+
:param config: Configuration to control the generator creation.
592+
:param orm_filename: "orm.yaml" file path so that the generator
593+
file can load the MetaData object
594+
:param config_filename: "config.yaml" file path so that the generator
595+
file can load the MetaData object
596+
:param src_stats_filename: A filename for where to read src stats from.
600597
Optional, if `None` this feature will be skipped
601-
overwrite_files: Whether to overwrite pre-existing vocabulary files
598+
:param overwrite_files: Whether to overwrite pre-existing vocabulary files
602599
603-
Returns:
604-
A string that is a valid Python module, once written to file.
600+
:return: A string that is a valid Python module, once written to file.
605601
"""
606602
row_generator_module_name: str = config.get("row_generators_module", None)
607603
story_generator_module_name = config.get("story_generators_module", None)

datafaker/providers.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,12 @@ def merge_with_constants(
249249
Merge a list of items with other items that must be placed at certain indices.
250250
251251
:param constants_at: A map of indices to objects that must be placed at
252-
those indices.
252+
those indices.
253253
:param xs: Items that fill in the gaps left by ``constants_at``.
254254
:return: ``xs`` with ``constants_at`` inserted at the appropriate
255-
points. If there are not enough elements in ``xs`` to fill in the gaps
256-
in ``constants_at``, the elements of ``constants_at`` after the gap
257-
are dropped.
255+
points. If there are not enough elements in ``xs`` to fill in the gaps
256+
in ``constants_at``, the elements of ``constants_at`` after the gap
257+
are dropped.
258258
"""
259259
outi = 0
260260
xi = 0
@@ -344,7 +344,7 @@ def choice(self, a: list[Mapping[str, T]]) -> T | None:
344344
Choose a value with equal probability.
345345
346346
:param a: The list of values to output. Each element is a mapping with
347-
a key ``value`` and the key is the value to return.
347+
a key ``value`` and the key is the value to return.
348348
:return: The chosen value.
349349
"""
350350
return self.choice_direct(a).get("value", None)
@@ -371,8 +371,8 @@ def zipf_choice(self, a: list[Mapping[str, T]], n: int | None = None) -> T | Non
371371
1/n times as frequently as the first value is chosen.
372372
373373
:param a: The list of rows to choose between, most frequent first.
374-
Each element is a mapping with a key ``value`` and the key is the
375-
value to return.
374+
Each element is a mapping with a key ``value`` and the key is the
375+
value to return.
376376
:return: The chosen value.
377377
"""
378378
c = self.zipf_choice_direct(a, n)
@@ -383,8 +383,8 @@ def weighted_choice(self, a: list[dict[str, Any]]) -> Any:
383383
Choice weighted by the count in the original dataset.
384384
385385
:param a: a list of dicts, each with a ``value`` key
386-
holding the value to be returned and a ``count`` key holding the
387-
number of that value found in the original dataset
386+
holding the value to be returned and a ``count`` key holding the
387+
number of that value found in the original dataset
388388
:return: The chosen ``value``.
389389
"""
390390
vs = []
@@ -406,9 +406,9 @@ def multivariate_normal_np(self, cov: dict[str, Any]) -> np.typing.NDArray:
406406
Return an array of values chosen from the given covariates.
407407
408408
:param cov: Keys are ``rank``: The number of values to output;
409-
``mN``: The mean of variable ``N`` (where ``N`` is between 0 and
410-
one less than ``rank``). ``cN_M`` (where 0 < ``N`` <= ``M`` < ``rank``):
411-
the covariance between the ``N``th and the ``M``th variables.
409+
``mN``: The mean of variable ``N`` (where ``N`` is between 0 and
410+
one less than ``rank``). ``cN_M`` (where 0 < ``N`` <= ``M`` < ``rank``):
411+
the covariance between the ``N``\th and the ``M``\th variables.
412412
:return: A numpy array of results.
413413
"""
414414
rank = int(cov["rank"])
@@ -473,10 +473,10 @@ def multivariate_normal(self, cov: dict[str, Any]) -> list[float]:
473473
Produce a list of values pulled from a multivariate distribution.
474474
475475
:param cov: A dict with various keys: ``rank`` is the number of
476-
output values, ``m0``, ``m1``, ... are the means of the
477-
distributions (``rank`` of them). ``c0_0``, ``c0_1``, ``c1_1``, ...
478-
are the covariates, ``cN_M`` is the covariate of the ``N``th and
479-
``M``th varaibles, with 0 <= ``N`` <= ``M`` < ``rank``.
476+
output values, ``m0``, ``m1``, ... are the means of the
477+
distributions (``rank`` of them). ``c0_0``, ``c0_1``, ``c1_1``, ...
478+
are the covariates, ``cN_M`` is the covariate of the ``N``\th and
479+
``M``\th varaibles, with 0 <= ``N`` <= ``M`` < ``rank``.
480480
:return: list of ``rank`` floating point values
481481
"""
482482
out: list[float] = self.multivariate_normal_np(cov).tolist()
@@ -487,11 +487,11 @@ def multivariate_lognormal(self, cov: dict[str, Any]) -> list[float]:
487487
Produce a list of values pulled from a multivariate distribution.
488488
489489
:param cov: A dict with various keys: ``rank`` is the number of
490-
output values, ``m0``, ``m1``, ... are the means of the
491-
distributions (``rank`` of them). ``c0_0``, ``c0_1``, ``c1_1``, ...
492-
are the covariates, ``cN_M`` is the covariate of the ``N``th and
493-
``M``th varaibles, with 0 <= ``N`` <= ``M`` < ``rank``. These
494-
are all the means and covariants of the logs of the data.
490+
output values, ``m0``, ``m1``, ... are the means of the
491+
distributions (``rank`` of them). ``c0_0``, ``c0_1``, ``c1_1``, ...
492+
are the covariates, ``cN_M`` is the covariate of the ``N``\th and
493+
``M``\th varaibles, with 0 <= ``N`` <= ``M`` < ``rank``. These
494+
are all the means and covariants of the logs of the data.
495495
:return: list of ``rank`` floating point values
496496
"""
497497
out: list[Any] = np.exp(self.multivariate_normal_np(cov)).tolist()
@@ -528,13 +528,13 @@ def alternatives(
528528
Pick between other generators.
529529
530530
:param alternative_configs: List of alternative generators.
531-
Each alternative has the following keys: "count" -- a weight for
532-
how often to use this alternative; "name" -- which generator
533-
for this partition, for example "composite"; "params" -- the
534-
parameters for this alternative.
531+
Each alternative has the following keys: "count" -- a weight for
532+
how often to use this alternative; "name" -- which generator
533+
for this partition, for example "composite"; "params" -- the
534+
parameters for this alternative.
535535
:param counts: A list of weights for each alternative. If None, the
536-
"count" value of each alternative is used. Each count is a dict
537-
with a "count" key.
536+
"count" value of each alternative is used. Each count is a dict
537+
with a "count" key.
538538
:return: list of values
539539
"""
540540
if counts is not None:
@@ -560,12 +560,12 @@ def with_constants_at(
560560
Insert constants into the results of a different generator.
561561
562562
:param constants_at: A dictionary of positions and objects to insert
563-
into the return list at those positions.
563+
into the return list at those positions.
564564
:param subgen: The name of the function to call to get the results
565-
that will have the constants inserted into.
565+
that will have the constants inserted into.
566566
:param params: Keyword arguments to the ``subgen`` function.
567567
:return: A list of results from calling ``subgen(**params)``
568-
with ``constants_at`` inserted in at the appropriate indices.
568+
with ``constants_at`` inserted in at the appropriate indices.
569569
"""
570570
if subgen not in self.PERMITTED_SUBGENS:
571571
logger.error(

datafaker/remove.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Functions and classes to undo the operations in create.py."""
2-
from typing import Any, Mapping
2+
from typing import Any, Mapping, Optional
33

44
from sqlalchemy import MetaData, delete
55

@@ -56,7 +56,7 @@ def remove_db_vocab(
5656
reinstate_vocab_foreign_key_constraints(metadata, meta_dict, config, dst_conn)
5757

5858

59-
def remove_db_tables(metadata: MetaData | None) -> None:
59+
def remove_db_tables(metadata: Optional[MetaData]) -> None:
6060
"""Drop the tables in the destination schema."""
6161
settings = get_settings()
6262
assert settings.dst_dsn, "Missing destination database settings"

datafaker/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def make_foreign_key_name(table_name: str, col_name: str) -> str:
488488
def remove_vocab_foreign_key_constraints(
489489
metadata: MetaData,
490490
config: Mapping[str, Any],
491-
dst_engine: Connection | Engine,
491+
dst_engine: Union[Connection, Engine],
492492
) -> None:
493493
"""
494494
Remove the foreign key constraints from vocabulary tables.
@@ -532,7 +532,7 @@ def reinstate_vocab_foreign_key_constraints(
532532
metadata: MetaData,
533533
meta_dict: Mapping[str, Any],
534534
config: Mapping[str, Any],
535-
dst_engine: Connection | Engine,
535+
dst_engine: Union[Connection, Engine],
536536
) -> None:
537537
"""
538538
Put the removed foreign keys back into the destination database.

0 commit comments

Comments
 (0)