Skip to main content

python tools to assist with standardized data ingestion workflows for the OS-Climate project

Project description

osc-ingest-tools

python tools to assist with standardized data ingestion workflows

Install from PyPi

pip install osc-ingest-tools

Examples

>>> from osc_ingest_trino import *

>>> import pandas as pd

>>> data = [['tom', 10], ['nick', 15], ['juli', 14]]

>>> df = pd.DataFrame(data, columns = ['First Name', 'Age In Years']).convert_dtypes()

>>> df
  First Name  Age In Years
0        tom            10
1       nick            15
2       juli            14

>>> enforce_sql_column_names(df)
  first_name  age_in_years
0        tom            10
1       nick            15
2       juli            14

>>> enforce_sql_column_names(df, inplace=True)

>>> df
  first_name  age_in_years
0        tom            10
1       nick            15
2       juli            14

>>> df.info(verbose=True)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 2 columns):
 #   Column        Non-Null Count  Dtype 
---  ------        --------------  ----- 
 0   first_name    3 non-null      string
 1   age_in_years  3 non-null      Int64 
dtypes: Int64(1), string(1)
memory usage: 179.0 bytes

>>> p = create_table_schema_pairs(df)

>>> print(p)
    first_name varchar,
    age_in_years bigint

>>> 

Adding custom type mappings to create_table_schema_pairs

>>> df = pd.DataFrame(data, columns = ['First Name', 'Age In Years'])

>>> enforce_sql_column_names(df, inplace=True)

>>> df.info(verbose=True)
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 2 columns):
 #   Column        Non-Null Count  Dtype 
---  ------        --------------  ----- 
 0   first_name    3 non-null      object
 1   age_in_years  3 non-null      int64 
dtypes: int64(1), object(1)
memory usage: 176.0+ bytes

>>> p = create_table_schema_pairs(df, typemap={'object':'varchar'})

>>> print(p)
    first_name varchar,
    age_in_years bigint

>>>

Development

Patches may be contributed via pull requests to https://github.com/os-climate/osc-ingest-tools.

All changes must pass the automated test suite, along with various static checks.

Black code style and isort import ordering are enforced.

Enabling automatic formatting via pre-commit is recommended:

pip install black isort pre-commit
pre-commit install

To ensure compliance with static check tools, developers may wish to run;

pip install black isort
# auto-sort imports
isort .
# auto-format code
black .

Code can then be tested using tox.

# run static checks and tests
tox
# run only tests
tox -e py3
# run only static checks
tox -e static
# run tests and produce a code coverage report
tox -e cov

Releasing

To release a new version of this library, authorized developers should;

  • Prepare a signed release commit updating version in setup.py
  • Tag the commit using Semantic Versioning prepended with "v"
  • Push the tag

E.g.,

git commit -sm "Release v0.3.3"
git tag v0.3.3
git push --follow-tags

A Github workflow will then automatically release the version to PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

osc-ingest-tools-0.3.3.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

osc_ingest_tools-0.3.3-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file osc-ingest-tools-0.3.3.tar.gz.

File metadata

  • Download URL: osc-ingest-tools-0.3.3.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.12

File hashes

Hashes for osc-ingest-tools-0.3.3.tar.gz
Algorithm Hash digest
SHA256 cdce697ef5f187de05d5d091279ac2717a46fa45467839d346b14bf66aa30401
MD5 71bbbb19ac6cd9ad9fd1e7ac85456227
BLAKE2b-256 ede1910bb32d08590f0941ffb13c74b792fdd0593e0a3e7e790ef9dab73dc172

See more details on using hashes here.

File details

Details for the file osc_ingest_tools-0.3.3-py3-none-any.whl.

File metadata

File hashes

Hashes for osc_ingest_tools-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 647d1a20edbabb7e8b5cc12a0be93607318f8da85d48f4daeb30b6bd29d4b6d7
MD5 89385cf43814233dc280e76b00c902be
BLAKE2b-256 2891c1a6e8cd05b3dd196b31faa60a7cf1ce411ee1d2d8f227129285a9b6e9d1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page