Skip to main content

Infers date format from examples, by using a series of pattern matching and rewriting rules to compute a "best guess" datetime.strptime format string give a list of example date strings.

Project description

pydateinfer

Python library to infer date format from examples. This is an actively maintained fork of the original dateinfer library by Jeffery Starr. It maintains python 2/3 compatibility and will be released as pydateinfer. Pull requests and issues welcome.

Table of Contents

Problem Statement

Imagine that you are given a large collection of documents and, as part of the extraction process, extract date information and store it in a normalized format. If the documents follow a single schema, the ideal approach is to craft a date parsing string for the schema. However, if the documents follow different schemas or if the contents are noisy (e.g. date fields were hand-populated), the development can become onerous.

This library makes a "best guess" on the proper date parsing string (datetime.strptime) based on examples in the file.

Installation

git clone https://github.com/nedap/dateinfer.git
cd dateinfer
pip install .

Usage

>>> import dateinfer
>>> dateinfer.infer(['Mon Jan 13 09:52:52 MST 2014', 'Tue Jan 21 15:30:00 EST 2014'])
'%a %b %d %H:%M:%S %Z %Y'
>>>

Give dateinfer.infer a list of example date strings. infer returns a datetime.strftime/strptime-compliant date format string for its "best guess" of a format string that will correctly parse the majority of the examples.

Development

Use the following to install the package locally for development purposes:

# create empty virtual environment
virtualenv venv --python=python3.7
source venv/bin/activate
# install dateinfer in editable mode
pip install -e .
# install development dependencies
pip install -r requirements.txt

You can run unit tests as follows:

python -m unittest dateinfer/tests.py

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

py_dateinfer-0.4.5.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

py_dateinfer-0.4.5-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file py_dateinfer-0.4.5.tar.gz.

File metadata

  • Download URL: py_dateinfer-0.4.5.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for py_dateinfer-0.4.5.tar.gz
Algorithm Hash digest
SHA256 0a4df1c80be414a1b7237d7e85b0b11cb315bfa432107dd7bc28765eb4674ea9
MD5 e0473da28d5f88b748c5b33a95bf3432
BLAKE2b-256 bd5cae2285c5c78dba01a80ba2d4c1e7bfa5209c272cb72bf662a05da68b3b3e

See more details on using hashes here.

File details

Details for the file py_dateinfer-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: py_dateinfer-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for py_dateinfer-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a121e24b3241168523c2bd3163da4c2d55bca4ec3f6aeb4f1dea03bba7909776
MD5 9c7e96ecaaa589cb784ac4e32094e0c8
BLAKE2b-256 2b9080931080c983eaed36dc4929e3f1adfce032e9f272762374023a8571601a

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