calcpy
Implementations of basic calculations in Python.
Installation
pip install --upgrade calcpy
Set-Alike APIs
Set-alike APIs operate objects with original order reserved and optional customized comparison function.
>>> from calcpy import unique
>>> unique([4, 3, 7, 3, 4])
[4, 3, 7]
List of APIs:
calcpy.unique(values, matcher=None)Remove duplicated entries.calcpy.concat(*args, matcher=None)Concatenate.calcpy.union(*args, matcher=None)Union.calcpy.intersect(*args, matcher=None)Intersection.calcpy.exclude(arg, *args, matcher=None)Remove follow-up arguments from the first.calcpy.xor(*args, matcher=None)Exclusive-or of follow-up parameters from the first parameter.calcpy.eq(*args, matcher=None)Check whether parameters are all equal.calcpy.ne(*args, matcher=None)Check whether parameters are all distinct.
Supported object types
listtuplesetnp.ndarraypd.Seriespd.DataFrame- others
On keyword parameter matcher:
The keyword parameter matcher is for customized comparison function.
By default, it is None, which uses the default way to compare two objects, i.e. compare them as a whole.
We can write customized binary functions to compare two objects. For example, we can compare the equality of two np.ndarrays using np.array_equal, or use the following customized function lower_matcher to compare two strs according to their lowercases:
>>> def lower_matcher(loper, roper):
... return loper.lower() == roper.lower()
...
>>> from calcpy import eq
>>> eq("Hello", "hello", "HELLO", matcher=lower_matcher)
True
calcpy also provide a class calcpy.matcher.PandasFrameMatcher for comparing pd.Seriess and pd.DataFrames.
-
calcpy.matcher.PandasFrameMatcher()Compare whether pandas objects as a whole. The same asloper.equals(roper). -
calcpy.matcher.PandasFrameMatcher("index")Compare index values of pandas objects. -
calcpy.matcher.PandasFrameMatcher("values")Compare values of pandas objects, ignoring the index values. -
calcpy.matcher.PandasFrameMatcher("series")Comparepd.DataFramein apd.Seriesway. By default, it isleft_series.equals(right_series).
For pd.DataFrame, it also provides a keyword parameter axis. It compares each row when it is set to 0 (the default value) or 'index', and compares each column if axis is set to 1 or 'column'.
Sequence APIs
Repetend Analysis
calcpy.sequence.min_repetend_len(): Get the mimimum length of repetends.
Usage Example:
>>> from calcpy.sequence import min_repetend_len
>>> min_repetend_len([1, 2, 3, 1, 2, 3, 1, 2])
3
Sequence Generator
calcpy.sequence.A276128(): Generator for the sequence OEIS A276128.
Usage Example:
>>> from calcpy.sequence import A276128
>>> print(list(A276128(14)))
[0, 0, 1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 21, 24]
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file calcpy-1.0.0.tar.gz.
File metadata
- Download URL: calcpy-1.0.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
470cd104856110fe34fda03393d867be05a02cf240374025630ed16f24e13a13
|
|
| MD5 |
ecadcebf7d18e629ca1ef91a3406627e
|
|
| BLAKE2b-256 |
f882f7d68df3437d182d281c3be9a9b2c25975f93e5c9df77dde9efe39f8a82d
|
File details
Details for the file calcpy-1.0.0-py3-none-any.whl.
File metadata
- Download URL: calcpy-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b068f0e469ddc3fd099918ad2379cca1bdb3cff0505587e4affd8641eaa722ea
|
|
| MD5 |
b3739a706548fa7dbf060e603bc82c8e
|
|
| BLAKE2b-256 |
e530c3dae6bb989d485d0e087771a0af63f1a75fc442114b26071ade20a279e6
|