mirror of
https://github.com/langchain-ai/datafusion.git
synced 2026-07-19 23:35:20 -04:00
add more math functions and unit tests to python crate (#748)
* rename functions * add test math functions * add python math functions
This commit is contained in:
+1
-1
@@ -31,7 +31,7 @@ libc = "0.2"
|
||||
tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "sync"] }
|
||||
rand = "0.7"
|
||||
pyo3 = { version = "0.14.1", features = ["extension-module"] }
|
||||
datafusion = { git = "https://github.com/apache/arrow-datafusion.git", rev = "5c1f8eb32c5f423d6c0e1f50350f9fe140135fdb" }
|
||||
datafusion = { git = "https://github.com/apache/arrow-datafusion.git", rev = "e4df37a4001423909964348289360da66acdd0a3" }
|
||||
|
||||
[lib]
|
||||
name = "datafusion"
|
||||
|
||||
+1
-1
@@ -145,7 +145,7 @@ Whenever rust code changes (your changes or via `git pull`):
|
||||
```bash
|
||||
# make sure you activate the venv using "source venv/bin/activate" first
|
||||
maturin develop
|
||||
python -m unittest discover tests
|
||||
python -m pytest
|
||||
```
|
||||
|
||||
## How to update dependencies
|
||||
|
||||
@@ -18,3 +18,8 @@ maturin
|
||||
toml
|
||||
pyarrow
|
||||
pytest
|
||||
black
|
||||
isort
|
||||
mypy
|
||||
numpy
|
||||
pandas
|
||||
|
||||
+141
-1
@@ -4,14 +4,30 @@
|
||||
#
|
||||
# pip-compile --generate-hashes
|
||||
#
|
||||
appdirs==1.4.4 \
|
||||
--hash=sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41 \
|
||||
--hash=sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128
|
||||
# via black
|
||||
attrs==21.2.0 \
|
||||
--hash=sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1 \
|
||||
--hash=sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb
|
||||
# via pytest
|
||||
black==21.7b0 \
|
||||
--hash=sha256:1c7aa6ada8ee864db745b22790a32f94b2795c253a75d6d9b5e439ff10d23116 \
|
||||
--hash=sha256:c8373c6491de9362e39271630b65b964607bc5c79c83783547d76c839b3aa219
|
||||
# via -r requirements.in
|
||||
click==8.0.1 \
|
||||
--hash=sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a \
|
||||
--hash=sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6
|
||||
# via black
|
||||
iniconfig==1.1.1 \
|
||||
--hash=sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3 \
|
||||
--hash=sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32
|
||||
# via pytest
|
||||
isort==5.9.2 \
|
||||
--hash=sha256:eed17b53c3e7912425579853d078a0832820f023191561fcee9d7cae424e0813 \
|
||||
--hash=sha256:f65ce5bd4cbc6abdfbe29afc2f0245538ab358c14590912df638033f157d555e
|
||||
# via -r requirements.in
|
||||
maturin==0.11.1 \
|
||||
--hash=sha256:1d8a276b4c4ac74ecf9624ebc718982cdd0f86581d6338c877d7eb2833b89a13 \
|
||||
--hash=sha256:56b1dc8651a40d024a0ac59720ffeb61a41059fcd836f1742ad828b78650fc1a \
|
||||
@@ -25,6 +41,37 @@ maturin==0.11.1 \
|
||||
--hash=sha256:e1598a844fdc7b5093749feb0b373fb2f7545033bb1f00779cfbf173906e374a \
|
||||
--hash=sha256:e60308dd43eb5f763126d0651827683141b12878541c6ede008f77ef655d1343
|
||||
# via -r requirements.in
|
||||
mypy==0.910 \
|
||||
--hash=sha256:088cd9c7904b4ad80bec811053272986611b84221835e079be5bcad029e79dd9 \
|
||||
--hash=sha256:0aadfb2d3935988ec3815952e44058a3100499f5be5b28c34ac9d79f002a4a9a \
|
||||
--hash=sha256:119bed3832d961f3a880787bf621634ba042cb8dc850a7429f643508eeac97b9 \
|
||||
--hash=sha256:1a85e280d4d217150ce8cb1a6dddffd14e753a4e0c3cf90baabb32cefa41b59e \
|
||||
--hash=sha256:3c4b8ca36877fc75339253721f69603a9c7fdb5d4d5a95a1a1b899d8b86a4de2 \
|
||||
--hash=sha256:3e382b29f8e0ccf19a2df2b29a167591245df90c0b5a2542249873b5c1d78212 \
|
||||
--hash=sha256:42c266ced41b65ed40a282c575705325fa7991af370036d3f134518336636f5b \
|
||||
--hash=sha256:53fd2eb27a8ee2892614370896956af2ff61254c275aaee4c230ae771cadd885 \
|
||||
--hash=sha256:704098302473cb31a218f1775a873b376b30b4c18229421e9e9dc8916fd16150 \
|
||||
--hash=sha256:7df1ead20c81371ccd6091fa3e2878559b5c4d4caadaf1a484cf88d93ca06703 \
|
||||
--hash=sha256:866c41f28cee548475f146aa4d39a51cf3b6a84246969f3759cb3e9c742fc072 \
|
||||
--hash=sha256:a155d80ea6cee511a3694b108c4494a39f42de11ee4e61e72bc424c490e46457 \
|
||||
--hash=sha256:adaeee09bfde366d2c13fe6093a7df5df83c9a2ba98638c7d76b010694db760e \
|
||||
--hash=sha256:b6fb13123aeef4a3abbcfd7e71773ff3ff1526a7d3dc538f3929a49b42be03f0 \
|
||||
--hash=sha256:b94e4b785e304a04ea0828759172a15add27088520dc7e49ceade7834275bedb \
|
||||
--hash=sha256:c0df2d30ed496a08de5daed2a9ea807d07c21ae0ab23acf541ab88c24b26ab97 \
|
||||
--hash=sha256:c6c2602dffb74867498f86e6129fd52a2770c48b7cd3ece77ada4fa38f94eba8 \
|
||||
--hash=sha256:ceb6e0a6e27fb364fb3853389607cf7eb3a126ad335790fa1e14ed02fba50811 \
|
||||
--hash=sha256:d9dd839eb0dc1bbe866a288ba3c1afc33a202015d2ad83b31e875b5905a079b6 \
|
||||
--hash=sha256:e4dab234478e3bd3ce83bac4193b2ecd9cf94e720ddd95ce69840273bf44f6de \
|
||||
--hash=sha256:ec4e0cd079db280b6bdabdc807047ff3e199f334050db5cbb91ba3e959a67504 \
|
||||
--hash=sha256:ecd2c3fe726758037234c93df7e98deb257fd15c24c9180dacf1ef829da5f921 \
|
||||
--hash=sha256:ef565033fa5a958e62796867b1df10c40263ea9ded87164d67572834e57a174d
|
||||
# via -r requirements.in
|
||||
mypy-extensions==0.4.3 \
|
||||
--hash=sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d \
|
||||
--hash=sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8
|
||||
# via
|
||||
# black
|
||||
# mypy
|
||||
numpy==1.21.0 \
|
||||
--hash=sha256:1a784e8ff7ea2a32e393cc53eb0003eca1597c7ca628227e34ce34eb11645a0e \
|
||||
--hash=sha256:2ba579dde0563f47021dcd652253103d6fd66165b18011dce1a0609215b2791e \
|
||||
@@ -54,11 +101,39 @@ numpy==1.21.0 \
|
||||
--hash=sha256:e80fe25cba41c124d04c662f33f6364909b985f2eb5998aaa5ae4b9587242cce \
|
||||
--hash=sha256:eda2829af498946c59d8585a9fd74da3f810866e05f8df03a86f70079c7531dd \
|
||||
--hash=sha256:fd0a359c1c17f00cb37de2969984a74320970e0ceef4808c32e00773b06649d9
|
||||
# via pyarrow
|
||||
# via
|
||||
# -r requirements.in
|
||||
# pandas
|
||||
# pyarrow
|
||||
packaging==21.0 \
|
||||
--hash=sha256:7dc96269f53a4ccec5c0670940a4281106dd0bb343f47b7471f779df49c2fbe7 \
|
||||
--hash=sha256:c86254f9220d55e31cc94d69bade760f0847da8000def4dfe1c6b872fd14ff14
|
||||
# via pytest
|
||||
pandas==1.3.0 \
|
||||
--hash=sha256:08eeff3da6a188e24db7f292b39a8ca9e073bf841fbbeadb946b3ad5c19d843e \
|
||||
--hash=sha256:1ff13eed501e07e7fb26a4ea18a846b6e5d7de549b497025601fd9ccb7c1d123 \
|
||||
--hash=sha256:522bfea92f3ef6207cadc7428bda1e7605dae0383b8065030e7b5d0266717b48 \
|
||||
--hash=sha256:7897326cae660eee69d501cbfa950281a193fcf407393965e1bc07448e1cc35a \
|
||||
--hash=sha256:798675317d0e4863a92a9a6bc5bd2490b5f6fef8c17b95f29e2e33f28bef9eca \
|
||||
--hash=sha256:7d3cd2c99faa94d717ca00ea489264a291ad7209453dffbf059bfb7971fd3a61 \
|
||||
--hash=sha256:823737830364d0e2af8c3912a28ba971296181a07950873492ed94e12d28c405 \
|
||||
--hash=sha256:872aa91e0f9ca913046ab639d4181a899f5e592030d954d28c2529b88756a736 \
|
||||
--hash=sha256:88864c1e28353b958b1f30e4193818519624ad9a1776921622a6a2a016d5d807 \
|
||||
--hash=sha256:92835113a67cbd34747c198d41f09f4b63f6fe11ca5643baebc7ab1e30e89e95 \
|
||||
--hash=sha256:98efc2d4983d5bb47662fe2d97b2c81b91566cb08b266490918b9c7d74a5ef64 \
|
||||
--hash=sha256:b10d7910ae9d7920a5ff7816d794d99acbc361f7b16a0f017d4fa83ced8cb55e \
|
||||
--hash=sha256:c554e6c9cf2d5ea1aba5979cc837b3649539ced0e18ece186f055450c86622e2 \
|
||||
--hash=sha256:c746876cdd8380be0c3e70966d4566855901ac9aaa5e4b9ccaa5ca5311457d11 \
|
||||
--hash=sha256:c81b8d91e9ae861eb4406b4e0f8d4dabbc105b9c479b3d1e921fba1d35b5b62a \
|
||||
--hash=sha256:e6b75091fa54a53db3927b4d1bc997c23c5ba6f87acdfe1ee5a92c38c6b2ed6a \
|
||||
--hash=sha256:ed4fc66f23fe17c93a5d439230ca2d6b5f8eac7154198d327dbe8a16d98f3f10 \
|
||||
--hash=sha256:f058c786e7b0a9e7fa5e0b9f4422e0ccdd3bf3aa3053c18d77ed2a459bd9a45a \
|
||||
--hash=sha256:fe7a549d10ca534797095586883a5c17d140d606747591258869c56e14d1b457
|
||||
# via -r requirements.in
|
||||
pathspec==0.9.0 \
|
||||
--hash=sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a \
|
||||
--hash=sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1
|
||||
# via black
|
||||
pluggy==0.13.1 \
|
||||
--hash=sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0 \
|
||||
--hash=sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d
|
||||
@@ -102,10 +177,75 @@ pytest==6.2.4 \
|
||||
--hash=sha256:50bcad0a0b9c5a72c8e4e7c9855a3ad496ca6a881a3641b4260605450772c54b \
|
||||
--hash=sha256:91ef2131a9bd6be8f76f1f08eac5c5317221d6ad1e143ae03894b862e8976890
|
||||
# via -r requirements.in
|
||||
python-dateutil==2.8.2 \
|
||||
--hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \
|
||||
--hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9
|
||||
# via pandas
|
||||
pytz==2021.1 \
|
||||
--hash=sha256:83a4a90894bf38e243cf052c8b58f381bfe9a7a483f6a9cab140bc7f702ac4da \
|
||||
--hash=sha256:eb10ce3e7736052ed3623d49975ce333bcd712c7bb19a58b9e2089d4057d0798
|
||||
# via pandas
|
||||
regex==2021.7.6 \
|
||||
--hash=sha256:0eb2c6e0fcec5e0f1d3bcc1133556563222a2ffd2211945d7b1480c1b1a42a6f \
|
||||
--hash=sha256:15dddb19823f5147e7517bb12635b3c82e6f2a3a6b696cc3e321522e8b9308ad \
|
||||
--hash=sha256:173bc44ff95bc1e96398c38f3629d86fa72e539c79900283afa895694229fe6a \
|
||||
--hash=sha256:1c78780bf46d620ff4fff40728f98b8afd8b8e35c3efd638c7df67be2d5cddbf \
|
||||
--hash=sha256:2366fe0479ca0e9afa534174faa2beae87847d208d457d200183f28c74eaea59 \
|
||||
--hash=sha256:2bceeb491b38225b1fee4517107b8491ba54fba77cf22a12e996d96a3c55613d \
|
||||
--hash=sha256:2ddeabc7652024803666ea09f32dd1ed40a0579b6fbb2a213eba590683025895 \
|
||||
--hash=sha256:2fe5e71e11a54e3355fa272137d521a40aace5d937d08b494bed4529964c19c4 \
|
||||
--hash=sha256:319eb2a8d0888fa6f1d9177705f341bc9455a2c8aca130016e52c7fe8d6c37a3 \
|
||||
--hash=sha256:3f5716923d3d0bfb27048242a6e0f14eecdb2e2a7fac47eda1d055288595f222 \
|
||||
--hash=sha256:422dec1e7cbb2efbbe50e3f1de36b82906def93ed48da12d1714cabcd993d7f0 \
|
||||
--hash=sha256:4c9c3155fe74269f61e27617529b7f09552fbb12e44b1189cebbdb24294e6e1c \
|
||||
--hash=sha256:4f64fc59fd5b10557f6cd0937e1597af022ad9b27d454e182485f1db3008f417 \
|
||||
--hash=sha256:564a4c8a29435d1f2256ba247a0315325ea63335508ad8ed938a4f14c4116a5d \
|
||||
--hash=sha256:59506c6e8bd9306cd8a41511e32d16d5d1194110b8cfe5a11d102d8b63cf945d \
|
||||
--hash=sha256:598c0a79b4b851b922f504f9f39a863d83ebdfff787261a5ed061c21e67dd761 \
|
||||
--hash=sha256:59c00bb8dd8775473cbfb967925ad2c3ecc8886b3b2d0c90a8e2707e06c743f0 \
|
||||
--hash=sha256:6110bab7eab6566492618540c70edd4d2a18f40ca1d51d704f1d81c52d245026 \
|
||||
--hash=sha256:6afe6a627888c9a6cfbb603d1d017ce204cebd589d66e0703309b8048c3b0854 \
|
||||
--hash=sha256:791aa1b300e5b6e5d597c37c346fb4d66422178566bbb426dd87eaae475053fb \
|
||||
--hash=sha256:8394e266005f2d8c6f0bc6780001f7afa3ef81a7a2111fa35058ded6fce79e4d \
|
||||
--hash=sha256:875c355360d0f8d3d827e462b29ea7682bf52327d500a4f837e934e9e4656068 \
|
||||
--hash=sha256:89e5528803566af4df368df2d6f503c84fbfb8249e6631c7b025fe23e6bd0cde \
|
||||
--hash=sha256:99d8ab206a5270c1002bfcf25c51bf329ca951e5a169f3b43214fdda1f0b5f0d \
|
||||
--hash=sha256:9a854b916806c7e3b40e6616ac9e85d3cdb7649d9e6590653deb5b341a736cec \
|
||||
--hash=sha256:b85ac458354165405c8a84725de7bbd07b00d9f72c31a60ffbf96bb38d3e25fa \
|
||||
--hash=sha256:bc84fb254a875a9f66616ed4538542fb7965db6356f3df571d783f7c8d256edd \
|
||||
--hash=sha256:c92831dac113a6e0ab28bc98f33781383fe294df1a2c3dfd1e850114da35fd5b \
|
||||
--hash=sha256:cbe23b323988a04c3e5b0c387fe3f8f363bf06c0680daf775875d979e376bd26 \
|
||||
--hash=sha256:ccb3d2190476d00414aab36cca453e4596e8f70a206e2aa8db3d495a109153d2 \
|
||||
--hash=sha256:d8bbce0c96462dbceaa7ac4a7dfbbee92745b801b24bce10a98d2f2b1ea9432f \
|
||||
--hash=sha256:db2b7df831c3187a37f3bb80ec095f249fa276dbe09abd3d35297fc250385694 \
|
||||
--hash=sha256:e586f448df2bbc37dfadccdb7ccd125c62b4348cb90c10840d695592aa1b29e0 \
|
||||
--hash=sha256:e5983c19d0beb6af88cb4d47afb92d96751fb3fa1784d8785b1cdf14c6519407 \
|
||||
--hash=sha256:e6a1e5ca97d411a461041d057348e578dc344ecd2add3555aedba3b408c9f874 \
|
||||
--hash=sha256:eaf58b9e30e0e546cdc3ac06cf9165a1ca5b3de8221e9df679416ca667972035 \
|
||||
--hash=sha256:ed693137a9187052fc46eedfafdcb74e09917166362af4cc4fddc3b31560e93d \
|
||||
--hash=sha256:edd1a68f79b89b0c57339bce297ad5d5ffcc6ae7e1afdb10f1947706ed066c9c \
|
||||
--hash=sha256:f080248b3e029d052bf74a897b9d74cfb7643537fbde97fe8225a6467fb559b5 \
|
||||
--hash=sha256:f9392a4555f3e4cb45310a65b403d86b589adc773898c25a39184b1ba4db8985 \
|
||||
--hash=sha256:f98dc35ab9a749276f1a4a38ab3e0e2ba1662ce710f6530f5b0a6656f1c32b58
|
||||
# via black
|
||||
six==1.16.0 \
|
||||
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \
|
||||
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254
|
||||
# via python-dateutil
|
||||
toml==0.10.2 \
|
||||
--hash=sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b \
|
||||
--hash=sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f
|
||||
# via
|
||||
# -r requirements.in
|
||||
# maturin
|
||||
# mypy
|
||||
# pytest
|
||||
tomli==1.0.4 \
|
||||
--hash=sha256:0713b16ff91df8638a6a694e295c8159ab35ba93e3424a626dd5226d386057be \
|
||||
--hash=sha256:be670d0d8d7570fd0ea0113bd7bb1ba3ac6706b4de062cc4c952769355c9c268
|
||||
# via black
|
||||
typing-extensions==3.10.0.0 \
|
||||
--hash=sha256:0ac0f89795dd19de6b97debb0c6af1c70987fd80a2d62d1958f7e56fcc31b497 \
|
||||
--hash=sha256:50b6f157849174217d0656f99dc82fe932884fb250826c18350e159ec6cdf342 \
|
||||
--hash=sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84
|
||||
# via mypy
|
||||
|
||||
+92
-40
@@ -63,7 +63,25 @@ fn in_list(
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! define_function {
|
||||
/// Current date and time
|
||||
#[pyfunction]
|
||||
fn now() -> expression::Expression {
|
||||
expression::Expression {
|
||||
// here lit(0) is a stub for conform to arity
|
||||
expr: logical_plan::now(logical_plan::lit(0)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a random value in the range 0.0 <= x < 1.0
|
||||
#[pyfunction]
|
||||
fn random() -> expression::Expression {
|
||||
expression::Expression {
|
||||
// here lit(0) is a stub for conform to arity
|
||||
expr: logical_plan::random(logical_plan::lit(0)),
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! define_unary_function {
|
||||
($NAME: ident) => {
|
||||
#[doc = "This function is not documented yet"]
|
||||
#[pyfunction]
|
||||
@@ -84,66 +102,82 @@ macro_rules! define_function {
|
||||
};
|
||||
}
|
||||
|
||||
define_function!(ascii, "Returns the numeric code of the first character of the argument. In UTF8 encoding, returns the Unicode code point of the character. In other multibyte encodings, the argument must be an ASCII character.");
|
||||
define_function!(sum);
|
||||
define_function!(
|
||||
define_unary_function!(sqrt, "sqrt");
|
||||
define_unary_function!(sin, "sin");
|
||||
define_unary_function!(cos, "cos");
|
||||
define_unary_function!(tan, "tan");
|
||||
define_unary_function!(asin, "asin");
|
||||
define_unary_function!(acos, "acos");
|
||||
define_unary_function!(atan, "atan");
|
||||
define_unary_function!(floor, "floor");
|
||||
define_unary_function!(ceil, "ceil");
|
||||
define_unary_function!(round, "round");
|
||||
define_unary_function!(trunc, "trunc");
|
||||
define_unary_function!(abs, "abs");
|
||||
define_unary_function!(signum, "signum");
|
||||
define_unary_function!(exp, "exp");
|
||||
define_unary_function!(ln, "ln");
|
||||
define_unary_function!(log2, "log2");
|
||||
define_unary_function!(log10, "log10");
|
||||
|
||||
define_unary_function!(ascii, "Returns the numeric code of the first character of the argument. In UTF8 encoding, returns the Unicode code point of the character. In other multibyte encodings, the argument must be an ASCII character.");
|
||||
define_unary_function!(sum);
|
||||
define_unary_function!(
|
||||
bit_length,
|
||||
"Returns number of bits in the string (8 times the octet_length)."
|
||||
);
|
||||
define_function!(btrim, "Removes the longest string containing only characters in characters (a space by default) from the start and end of string.");
|
||||
define_function!(
|
||||
define_unary_function!(btrim, "Removes the longest string containing only characters in characters (a space by default) from the start and end of string.");
|
||||
define_unary_function!(
|
||||
character_length,
|
||||
"Returns number of characters in the string."
|
||||
);
|
||||
define_function!(chr, "Returns the character with the given code.");
|
||||
define_function!(concat_ws, "Concatenates all but the first argument, with separators. The first argument is used as the separator string, and should not be NULL. Other NULL arguments are ignored.");
|
||||
define_function!(initcap, "Converts the first letter of each word to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters.");
|
||||
define_function!(left, "Returns first n characters in the string, or when n is negative, returns all but last |n| characters.");
|
||||
define_function!(lower, "Converts the string to all lower case");
|
||||
define_function!(lpad, "Extends the string to length length by prepending the characters fill (a space by default). If the string is already longer than length then it is truncated (on the right).");
|
||||
define_function!(ltrim, "Removes the longest string containing only characters in characters (a space by default) from the start of string.");
|
||||
define_function!(
|
||||
define_unary_function!(chr, "Returns the character with the given code.");
|
||||
define_unary_function!(concat_ws, "Concatenates all but the first argument, with separators. The first argument is used as the separator string, and should not be NULL. Other NULL arguments are ignored.");
|
||||
define_unary_function!(initcap, "Converts the first letter of each word to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters.");
|
||||
define_unary_function!(left, "Returns first n characters in the string, or when n is negative, returns all but last |n| characters.");
|
||||
define_unary_function!(lower, "Converts the string to all lower case");
|
||||
define_unary_function!(lpad, "Extends the string to length length by prepending the characters fill (a space by default). If the string is already longer than length then it is truncated (on the right).");
|
||||
define_unary_function!(ltrim, "Removes the longest string containing only characters in characters (a space by default) from the start of string.");
|
||||
define_unary_function!(
|
||||
md5,
|
||||
"Computes the MD5 hash of the argument, with the result written in hexadecimal."
|
||||
);
|
||||
define_function!(now);
|
||||
define_function!(octet_length, "Returns number of bytes in the string. Since this version of the function accepts type character directly, it will not strip trailing spaces.");
|
||||
define_function!(random, "Returns a random value in the range 0.0 <= x < 1.0");
|
||||
define_function!(
|
||||
define_unary_function!(octet_length, "Returns number of bytes in the string. Since this version of the function accepts type character directly, it will not strip trailing spaces.");
|
||||
define_unary_function!(
|
||||
replace,
|
||||
"Replaces all occurrences in string of substring from with substring to."
|
||||
);
|
||||
define_function!(repeat, "Repeats string the specified number of times.");
|
||||
define_function!(
|
||||
define_unary_function!(repeat, "Repeats string the specified number of times.");
|
||||
define_unary_function!(
|
||||
regexp_replace,
|
||||
"Replaces substring(s) matching a POSIX regular expression"
|
||||
);
|
||||
define_function!(
|
||||
define_unary_function!(
|
||||
reverse,
|
||||
"Reverses the order of the characters in the string."
|
||||
);
|
||||
define_function!(right, "Returns last n characters in the string, or when n is negative, returns all but first |n| characters.");
|
||||
define_function!(rpad, "Extends the string to length length by appending the characters fill (a space by default). If the string is already longer than length then it is truncated.");
|
||||
define_function!(rtrim, "Removes the longest string containing only characters in characters (a space by default) from the end of string.");
|
||||
define_function!(sha224);
|
||||
define_function!(sha256);
|
||||
define_function!(sha384);
|
||||
define_function!(sha512);
|
||||
define_function!(split_part, "Splits string at occurrences of delimiter and returns the n'th field (counting from one).");
|
||||
define_function!(starts_with, "Returns true if string starts with prefix.");
|
||||
define_function!(strpos,"Returns starting index of specified substring within string, or zero if it's not present. (Same as position(substring in string), but note the reversed argument order.)");
|
||||
define_function!(substr);
|
||||
define_function!(
|
||||
define_unary_function!(right, "Returns last n characters in the string, or when n is negative, returns all but first |n| characters.");
|
||||
define_unary_function!(rpad, "Extends the string to length length by appending the characters fill (a space by default). If the string is already longer than length then it is truncated.");
|
||||
define_unary_function!(rtrim, "Removes the longest string containing only characters in characters (a space by default) from the end of string.");
|
||||
define_unary_function!(sha224);
|
||||
define_unary_function!(sha256);
|
||||
define_unary_function!(sha384);
|
||||
define_unary_function!(sha512);
|
||||
define_unary_function!(split_part, "Splits string at occurrences of delimiter and returns the n'th field (counting from one).");
|
||||
define_unary_function!(starts_with, "Returns true if string starts with prefix.");
|
||||
define_unary_function!(strpos,"Returns starting index of specified substring within string, or zero if it's not present. (Same as position(substring in string), but note the reversed argument order.)");
|
||||
define_unary_function!(substr);
|
||||
define_unary_function!(
|
||||
to_hex,
|
||||
"Converts the number to its equivalent hexadecimal representation."
|
||||
);
|
||||
define_function!(translate, "Replaces each character in string that matches a character in the from set with the corresponding character in the to set. If from is longer than to, occurrences of the extra characters in from are deleted.");
|
||||
define_function!(trim, "Removes the longest string containing only characters in characters (a space by default) from the start, end, or both ends (BOTH is the default) of string.");
|
||||
define_function!(upper, "Converts the string to all upper case.");
|
||||
define_function!(avg);
|
||||
define_function!(min);
|
||||
define_function!(max);
|
||||
define_function!(count);
|
||||
define_unary_function!(translate, "Replaces each character in string that matches a character in the from set with the corresponding character in the to set. If from is longer than to, occurrences of the extra characters in from are deleted.");
|
||||
define_unary_function!(trim, "Removes the longest string containing only characters in characters (a space by default) from the start, end, or both ends (BOTH is the default) of string.");
|
||||
define_unary_function!(upper, "Converts the string to all upper case.");
|
||||
define_unary_function!(avg);
|
||||
define_unary_function!(min);
|
||||
define_unary_function!(max);
|
||||
define_unary_function!(count);
|
||||
|
||||
/*
|
||||
#[pyfunction]
|
||||
@@ -263,5 +297,23 @@ pub fn init(module: &PyModule) -> PyResult<()> {
|
||||
module.add_function(wrap_pyfunction!(max, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(avg, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(udaf, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(sqrt, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(sin, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(cos, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(tan, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(asin, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(acos, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(atan, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(floor, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(ceil, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(round, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(trunc, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(abs, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(signum, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(exp, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(ln, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(log2, module)?)?;
|
||||
module.add_function(wrap_pyfunction!(log10, module)?)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import numpy as np
|
||||
import pyarrow as pa
|
||||
import pytest
|
||||
from datafusion import ExecutionContext
|
||||
from datafusion import functions as f
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def df():
|
||||
ctx = ExecutionContext()
|
||||
# create a RecordBatch and a new DataFrame from it
|
||||
batch = pa.RecordBatch.from_arrays([pa.array([0.1, -0.7, 0.55])], names=["value"])
|
||||
return ctx.create_dataframe([[batch]])
|
||||
|
||||
|
||||
def test_math_functions(df):
|
||||
values = np.array([0.1, -0.7, 0.55])
|
||||
col_v = f.col("value")
|
||||
df = df.select(
|
||||
f.abs(col_v),
|
||||
f.sin(col_v),
|
||||
f.cos(col_v),
|
||||
f.tan(col_v),
|
||||
f.asin(col_v),
|
||||
f.acos(col_v),
|
||||
f.exp(col_v),
|
||||
f.ln(col_v + f.lit(1)),
|
||||
f.log2(col_v + f.lit(1)),
|
||||
f.log10(col_v + f.lit(1)),
|
||||
)
|
||||
result = df.collect()
|
||||
assert len(result) == 1
|
||||
result = result[0]
|
||||
np.testing.assert_array_almost_equal(result.column(0), np.abs(values))
|
||||
np.testing.assert_array_almost_equal(result.column(1), np.sin(values))
|
||||
np.testing.assert_array_almost_equal(result.column(2), np.cos(values))
|
||||
np.testing.assert_array_almost_equal(result.column(3), np.tan(values))
|
||||
np.testing.assert_array_almost_equal(result.column(4), np.arcsin(values))
|
||||
np.testing.assert_array_almost_equal(result.column(5), np.arccos(values))
|
||||
np.testing.assert_array_almost_equal(result.column(6), np.exp(values))
|
||||
np.testing.assert_array_almost_equal(result.column(7), np.log(values + 1.0))
|
||||
np.testing.assert_array_almost_equal(result.column(8), np.log2(values + 1.0))
|
||||
np.testing.assert_array_almost_equal(result.column(9), np.log10(values + 1.0))
|
||||
@@ -46,10 +46,4 @@ def test_string_functions(df):
|
||||
"9033e0e305f247c0c3c80d0c7848c8b3",
|
||||
]
|
||||
)
|
||||
assert result.column(1) == pa.array(
|
||||
[
|
||||
"hello",
|
||||
"world",
|
||||
"!",
|
||||
]
|
||||
)
|
||||
assert result.column(1) == pa.array(["hello", "world", "!"])
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# under the License.
|
||||
|
||||
from typing import List
|
||||
|
||||
import pyarrow as pa
|
||||
import pyarrow.compute as pc
|
||||
import pytest
|
||||
|
||||
Reference in New Issue
Block a user