Skip to main content

Column type inference and type-aware cleaning: numbers, currency, percentages, booleans, nulls, dates.

Project description

typemonkey

Column type inference and type-aware cleaning for messy tabular data. Infer whether a column is an integer, float, currency, percentage, boolean, date, or free-text string — then clean it to that type. Numbers buried in currency symbols, thousands separators, European decimal commas, accounting parentheses, and percent signs come out as plain Python numbers; a column's worth of yes/Y/1/true come out as bool; twenty-plus spellings of "null" collapse to None.

Part of the monkey toolkit. Delegates date detection to datemonkey and value normalisation to cleanmonkey — it does not reinvent either.

Install

pip install typemonkey

Quick start

from typemonkey import infer_type, clean_numeric, clean_boolean, clean_column

profile = infer_type(["$1,234.56", "$2,000.00", "$3.50"])
profile.type          # TypeName.CURRENCY
profile.confidence    # 1.0
profile.locale        # "us"

clean_numeric(["$1,234.56", "(50)", "12%", "N/A"]).values
# [1234.56, -50, 0.12, None]      # parens = negative, 12% = 0.12, N/A = null

clean_numeric(["1.234,56", "3,50"], locale="eu").values
# [1234.56, 3.5]                  # European decimal comma

clean_boolean(["yes", "NO", "1", "0", "maybe"]).values
# [True, False, True, False, None]   # "maybe" recorded in .failures

clean_column(["01234", "07090", "02139"]).values
# ['01234', '07090', '02139']     # zero-padded IDs preserved as strings

Every entry point returns a typed dataclass (ColumnProfile, CleanResult), not a dict. CleanResult.failures lists (index, original) for non-null values that didn't parse, so "missing" is never confused with "empty".

ColumnProfile.needs_attention is a triage hint for human/LLM review: True only when typemonkey can name an ambiguity (attention_reasons), such as a DD/MM-ambiguous date that still reports confidence == 1.0, a type that only just cleared the threshold, or a string that was almost a real type — the cases plain confidence can't express.

What it recognises

  • Numbersint, float, with thousands separators, apostrophe/space grouping, leading +/-, accounting (parentheses) negatives.
  • Currency$ € £ ¥ ₹ ... symbols and ISO codes (USD, EUR, ...).
  • Percentages"12%", "8 %"0.12, 0.08 (or keep as 12, 8).
  • Booleanstrue/false, t/f, yes/no, y/n, on/off, 1/0.
  • Dates — via datemonkey (ISO, US/EU slash and dash, ambiguity reporting).
  • Nulls — 20+ spellings (N/A, #N/A, null, none, -, unknown, …).
  • Preserve-as-string — zero-padded IDs, Zip+4, phone numbers.
  • Locale — US 1,234.56 vs European 1.234,56, auto-detected per column.

CLI

printf '$1,234.56\n$2,000.00\n$3.50\n' | typemonkey profile      # JSON report
printf '12%%\n8 %%\nN/A\n'             | typemonkey clean         # cleaned values
typemonkey clean --type integer column.txt

typemonkey profile prints a JSON ColumnProfile; typemonkey clean prints one cleaned value per line (blank for nulls) and exits non-zero if any non-null value failed to parse.

Using with AI assistants

See SKILL.md for an LLM-oriented quick reference (decision table, worked examples, anti-patterns).

Deliberate tradeoffs

Some behaviour is intentional and might look like a bug — bare 5-digit numbers aren't treated as zips, all-0/1 columns are integers not booleans, Excel serials report numeric. See LIMITATIONS.md for the rationale and escape hatch on each.

License

MIT

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

typemonkey-1.2.0.tar.gz (58.4 kB view details)

Uploaded Source

Built Distribution

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

typemonkey-1.2.0-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

Details for the file typemonkey-1.2.0.tar.gz.

File metadata

  • Download URL: typemonkey-1.2.0.tar.gz
  • Upload date:
  • Size: 58.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for typemonkey-1.2.0.tar.gz
Algorithm Hash digest
SHA256 33c8b12950166a9b95fc94d9fc687c31658ef246ebabb1d1766966e91f15d965
MD5 d2c40446125c4d276dfbd54c6f7aced7
BLAKE2b-256 caa4cf77e4914ff862bb9d53caefc2bc4cd988b9e061fb48b86b3966e816a1f0

See more details on using hashes here.

File details

Details for the file typemonkey-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: typemonkey-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 33.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for typemonkey-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee2f79ddc7c2b604cc7f10ad71b61520e367453f8b37a889fc1f0f86a8be9583
MD5 b95dce16fef31406d1dfa278b26cbdb0
BLAKE2b-256 23b87519640e403af0ca2e9cade76b681629a64fbf757d675f03532f3d473b9d

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