Skip to main content

Extensible mathematical expression analyzer with callbacks for variables and functions

Project description

MaExPa (__Ma__thematical __Ex__pression __Pa__rser) is library providing a simple algebraic expression analyser, with callbacks for variable replacement and function calls, and support for implicit support of NumPy arrays.

Aims

The goal of this library is to provide an easy way to do custom calculations on an existing dataset. If a dataset provides several fields, this library allows the end user to combine and transform fields to suit their whishes. Fields are exposed as variables in the expression, and are retrived by means of a callback function where the user-provided expression requests a mathematical variable.

Usage

MaExPa provides on main class, maexpa.Expression that compiles and executes user-provided mathematical expressions. A very simple use is this:

import maexpa

expr = maexpa.Expression( "3*5" )
print( expr() )

A more complicated use case with a replacement for variables is:

import numpy
import maexpa

expr = maexpa.Expression( "item/total*100." )

def vars_callback( name ):
	if name == "item":
		return numpy.asarray( [ 1., 2., 3. ] )

	if name == "total":
		return numpy.asarray( [ 10., 10., 10. ] )

	raise Exception( "Unknown variable {:s}".format( name ) )

print( expr( var = vars_callback ) )

which will show [10. 20. 30.].

License

The library is licensed under version 2.0 of the Apache License, see the LICENSE file for the full terms and conditions.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

maexpa-0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

maexpa-0.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file maexpa-0.1.tar.gz.

File metadata

  • Download URL: maexpa-0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

File hashes

Hashes for maexpa-0.1.tar.gz
Algorithm Hash digest
SHA256 d24015df21f33f84493bc7ed2f9cf2a126095d10cf0f7d3e730b3d2b70f46311
MD5 a63e8d56446c7aef401c30fcd1305787
BLAKE2b-256 dd1290e1003b5ae0589b00d154361589e4714dceb349bd23b5ba4bb204cc0201

See more details on using hashes here.

Provenance

File details

Details for the file maexpa-0.1-py3-none-any.whl.

File metadata

  • Download URL: maexpa-0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

File hashes

Hashes for maexpa-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1525231fd982725ac85f99480bc306d5ac78db4c7385c97dca24cb1884c86cce
MD5 80ccbe42b2408ed677f6d0bae9d15380
BLAKE2b-256 c97294a9ca78b4e652ab8710a5d574a4a04b954d61823602fda21385e599af8c

See more details on using hashes here.

Provenance

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