Giter Club home page Giter Club logo

moj-analytical-services.data_generator's Introduction

data_generator

unit-tests.yml

Generates data using faker and our meta data schemas. This package expects meta data that conforms to the ETL Manager schema repo here

from data_generator.data_generator import MetaFaker

meta = {
    "columns": [
        {
            "name": "my_int",
            "type": "int",
            "minimum": 10,
            "maximum": 20,
            "nullable": True
        },
        {
            "name": "my_character_enum",
            "type": "character",
            "enum": ["a", "b", "c"]
        },
        {
            "name": "my_email",
            "type": "character",
        },
        {
            "name": "my_datetime",
            "type": "datetime",
        }
    ]
}

sc = {
    "my_email": "email",
}

mf = MetaFaker(meta=meta, special_cols=sc)
mf.generate_row()

Would return something like this:

{
    'my_int': 18,
    'my_character_enum': 'a',
    'my_email': '[email protected]',
    'my_datetime': '1988-05-24 10:00:57',
}

Can also write to jsonl or csv

#csv
mf.write_data_to_csv("test.csv", total_rows=10)

# jsonl 
mf.write_data_to_jsonl("test.jsonl", 10)

Special Case Characters

In the above example you could see that we stated that the my_email column should produce email-like strings in the following way.

...
sc = {
    "my_email": "email",
}
...

The sc parameter works for the key/value pair where the key is the column name (in the data to be generated) and the value is a string that is the name of the provider in the Faker package that is called under the hood of this package (this line shows how).. To find what other types of specific strings you can generate e.g. address, name, last_name, etc. Please look at Faker providers.

Setting a seed

If you want to get the same data every time you run, set the seed.

mf = MetaFaker(meta=meta, special_cols=sc)

mf.seed = 888

Changing the locale

As of v0.0.4, this package defaults to British special characters where they are available (e.g. address). This can be changed by:

mf = MetaFaker(meta=meta, special_cols=sc, locale="en_US")

For a full list of locales, see https://faker.readthedocs.io/en/master/locales.html.

moj-analytical-services.data_generator's People

Contributors

isichei avatar thomas-hirsch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.