Settings, server connection¶
Session¶
crandas.base.session
Connection to server¶
base.Session.endpoint
Query arguments¶
Query arguments
Adding nonces¶
import crandas as cd
from crandas.transactions import Transaction
a = cd.DataFrame({"test": [1]})
f1 = a.filter(lambda x: 1, add_nonce=True)
f2 = a.filter(lambda x: 1, add_nonce=True)
assert f1.name != f2.name
with Transaction(add_nonce=True):
a = cd.DataFrame({"test": [1]})
f1 = a.filter(lambda x: 1)
f2 = a.filter(lambda x: 1)
assert f1.result.name != f2.result.name
Setting the bitlength¶
(to be removed in the future)
import crandas as cd
from crandas.transactions import Transaction
"""Test configurable bitlength for operations"""
def test_with_bitlength(bl):
# test with numbers close 2**bl-1 so that the comparison intervals are close to 2**bl
a = cd.DataFrame(
{
"row": [
-(2 ** (bl - 1)) + 1,
-(2 ** (bl - 1)) + 2,
2 ** (bl - 1) - 2,
2 ** (bl - 1) - 1,
]
}
)
assert (
sum(a.assign(test=lambda x: x.row >= -(2 ** (bl - 1)), bitlength=bl).open()["test"])
== 4
)
assert (
sum(a.assign(test=lambda x: x.row >= -(2 ** (bl - 1)) + 1, bitlength=bl).open()["test"])
== 4
)
assert (
sum(a.assign(test=lambda x: x.row >= -(2 ** (bl - 1)) + 2, bitlength=bl).open()["test"])
== 3
)
assert (
sum(a.assign(test=lambda x: x.row >= -(2 ** (bl - 1)) + 3, bitlength=bl).open()["test"])
== 2
)
assert (
sum(a.assign(test=lambda x: x.row >= 2 ** (bl - 1) - 3, bitlength=bl).open()["test"])
== 2
)
assert (
sum(a.assign(test=lambda x: x.row >= 2 ** (bl - 1) - 2, bitlength=bl).open()["test"])
== 2
)
assert (
sum(a.assign(test=lambda x: x.row >= 2 ** (bl - 1) - 1, bitlength=bl).open()["test"])
== 1
)
assert (
sum(a.assign(test=lambda x: x.row >= 2 ** (bl - 1), bitlength=bl).open()["test"]) == 0
)
test_with_bitlength(25)
test_with_bitlength(32)
"""Test configuring a bitlength for a transaction"""
with Transaction(bitlength=32):
bl = 32
a = cd.DataFrame(
{
"row": [
-(2 ** (bl - 1)) + 1,
-(2 ** (bl - 1)) + 2,
2 ** (bl - 1) - 2,
2 ** (bl - 1) - 1,
]
}
)
res1 = a.assign(test=lambda x: x.row >= -(2 ** (bl - 1))).open()
res2 = a.assign(test=lambda x: x.row >= -(2 ** (bl - 1)) + 1).open()
res3 = a.assign(test=lambda x: x.row >= -(2 ** (bl - 1)) + 2).open()
res4 = a.assign(test=lambda x: x.row >= -(2 ** (bl - 1)) + 3).open()
res5 = a.assign(test=lambda x: x.row >= 2 ** (bl - 1) - 3).open()
res6 = a.assign(test=lambda x: x.row >= 2 ** (bl - 1) - 2).open()
res7 = a.assign(test=lambda x: x.row >= 2 ** (bl - 1) - 1).open()
res8 = a.assign(test=lambda x: x.row >= 2 ** (bl - 1)).open()
assert sum(res1.result["test"]) == 4
assert sum(res2.result["test"]) == 4
assert sum(res3.result["test"]) == 3
assert sum(res4.result["test"]) == 2
assert sum(res5.result["test"]) == 2
assert sum(res6.result["test"]) == 2
assert sum(res7.result["test"]) == 1
assert sum(res8.result["test"]) == 0