Skip to main content

A flexible pairwise tool written in Python.

Project description

https://badge.fury.io/py/covertable.svg https://github.com/walkframe/covertable/actions/workflows/python.yaml/badge.svg https://codecov.io/gh/walkframe/covertable/branch/master/graph/badge.svg https://img.shields.io/badge/code%20style-black-000000.svg https://img.shields.io/badge/License-Apache%202.0-blue.svg

Requirements

  • Python: 3.3 or later.

    • Tested with 3.7, 3.11

Installation

$ pip install covertable

Usage

Just import covertable and call make function.

>>> from covertable import make, sorters, criteria

>>> machine_list = ['iphone', 'pixel']
>>> os_list = ['ios', 'android']
>>> browser_list = ['FireFox', 'Chrome', 'Safari']
>>> # list input and output
>>> make(
...     [machine_list, os_list, browser_list],  # list factors
...     length=2,  # default: 2
...     sorter=sorters.random,  # default: sorters.hash
...     criterion=criteria.simple,  # default: criteria.greedy
...     seed=100,  # default: ''
...     pre_filter=lambda row: not(row[1] == 'android' and row[0] != 'pixel') and not(row[1] == 'ios' and row[0] != 'iphone'),  # default: None
... )
[
  ['pixel', 'android', 'Safari'],
  ['iphone', 'ios', 'Chrome'],
  ['iphone', 'ios', 'Safari'],
  ['pixel', 'android', 'Chrome'],
  ['pixel', 'android', 'FireFox'],
  ['iphone', 'ios', 'FireFox']
]


>>> # dict input and output
>>> make(
...     {'machine': machine_list, 'os': os_list, 'browser': browser_list},  # dict factors
...     length=2,  # default: 2
...     tolerance=3,  # default: 0
...     post_filter=lambda row: not(row['os'] == 'android' and row['machine'] != 'pixel') and not(row['os'] == 'ios' and row['machine'] != 'iphone'),  # default: None
... )
[
  {'machine': 'pixel', 'browser': 'Chrome', 'os': 'android'},
  {'machine': 'pixel', 'browser': 'FireFox', 'os': 'android'},
  {'machine': 'iphone', 'os': 'ios', 'browser': 'Chrome'},
  {'os': 'ios', 'browser': 'FireFox', 'machine': 'iphone'}
]

Options

covertable.make function has options as keyword argument.

All options are omittable.

length

Number of factors to be covered. (default: 2)

Obviously the more it increases, the more number of combinations increases.

sorter

Combinations depend on the order of spreading all over the rows.

You can choice a sorter from the following:

sorters.random:

This makes different combinations everytime. (fastest)

sorters.hash:

This makes combinations depending on hash of the pair and seed. (default)

  • It receives seed and useCache options.

    • seed option decides the order of storing from unstored pairs, therefore it outputs the same result every time when number of factors and seed are the same.

    • useCache option decide if using cache of hash or not. (default: true)

      • It is around 10% faster than setting useCache off.

criterion

criteria.simple:

This extracts any pairs that can be stored into the processing row.

criteria.greedy:

This attempts to make most efficient combinations. (default)

  • These combinations are not always shorter than simple criterion.

  • It receives tolerance option.

pre_filter

This means a function to filter beforehand.

It receives an argument row as object type.

When the function returns False, the row combination will not be registered.

  • If factors type is Array, you should specify an index at the subscript like row => row[1] < 6.

  • If factors type is Object, you should specify a key at the subscript like row => row['month'] < 6

post_filter

This means a function to filter later.

The usage is the same as preFilter, only the difference is the timing of the call. It will delete rows not matched this function at the last.

For this reason, the final test cases may not satisfy the factors coverage.

Development

# preparation
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ pip install -r dev_requirements.txt

# testing
(venv) $ pytest

Publish

(venv) $ python setup.py sdist bdist_wheel
(venv) $ twine upload --repository pypi dist/*

More info

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

covertable-3.0.0rc0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

covertable-3.0.0rc0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file covertable-3.0.0rc0.tar.gz.

File metadata

  • Download URL: covertable-3.0.0rc0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for covertable-3.0.0rc0.tar.gz
Algorithm Hash digest
SHA256 c9b7cef2ff6430f40e714e2eb5888fc0e485fbdfc9cee87483d0272a8144a052
MD5 bbbcafac65d90b077f110a8bb05adf39
BLAKE2b-256 8864f936d8abbe72fbdcbdebc12777adf6c08ed5b028ebb1c2653f17695595da

See more details on using hashes here.

File details

Details for the file covertable-3.0.0rc0-py3-none-any.whl.

File metadata

  • Download URL: covertable-3.0.0rc0-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for covertable-3.0.0rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 d434ec6a02f7608a5a458bdee3ed98d241898b518ad8693c78289b7ebdced974
MD5 650d7bc8e7e9fcbeac2b812568770df1
BLAKE2b-256 6c5e93a7eb2f898f2b68a621ee476a96637f04d9e4cc96b7b53cb76effcbda3d

See more details on using hashes here.

Supported by

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