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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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