mirror of
https://github.com/tgorordo/smithy.git
synced 2026-06-05 16:22:15 -07:00
some formatting and add cli compilation
This commit is contained in:
parent
8836c49091
commit
4a624a4847
9 changed files with 115 additions and 61 deletions
|
|
@ -23,18 +23,23 @@ def _():
|
|||
@app.cell
|
||||
def _(mo, pl):
|
||||
df = pl.read_csv(mo.notebook_dir() / "test_ballot.csv")
|
||||
df = df.with_columns([ pl.col(c) # make safe, clean up
|
||||
.cast(pl.Utf8)
|
||||
.str.strip_chars()
|
||||
.cast(pl.Int64, strict=False).fill_null(df.width + 1)
|
||||
for c in df.columns ])
|
||||
df = df.with_columns(
|
||||
[
|
||||
pl.col(c) # make safe, clean up
|
||||
.cast(pl.Utf8)
|
||||
.str.strip_chars()
|
||||
.cast(pl.Int64, strict=False)
|
||||
.fill_null(df.width + 1)
|
||||
for c in df.columns
|
||||
]
|
||||
)
|
||||
df
|
||||
return (df,)
|
||||
|
||||
|
||||
@app.cell
|
||||
def _(df, smith_set):
|
||||
smith_set(df) # find the smith set (should be "Alice" and "Bob" as a pair)
|
||||
smith_set(df) # find the smith set (should be "Alice" and "Bob" as a pair)
|
||||
return
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,35 +1,41 @@
|
|||
import polars as pl
|
||||
from smithy import smith_set
|
||||
|
||||
|
||||
def test_condorcet():
|
||||
df = pl.DataFrame({
|
||||
'A': [1, 1, 2, 1],
|
||||
'B': [2, 2, 1, 2],
|
||||
'C': [3, 3, 3, 3],
|
||||
})
|
||||
assert smith_set(df) == ['A']
|
||||
df = pl.DataFrame(
|
||||
{
|
||||
"A": [1, 1, 2, 1],
|
||||
"B": [2, 2, 1, 2],
|
||||
"C": [3, 3, 3, 3],
|
||||
}
|
||||
)
|
||||
assert smith_set(df) == ["A"]
|
||||
|
||||
|
||||
def test_rockpprscrcycle():
|
||||
df = pl.DataFrame({
|
||||
'A': [1, 2, 3],
|
||||
'B': [2, 3, 1],
|
||||
'C': [3, 1, 2],
|
||||
})
|
||||
assert smith_set(df) == ['A', 'B', 'C']
|
||||
df = pl.DataFrame(
|
||||
{
|
||||
"A": [1, 2, 3],
|
||||
"B": [2, 3, 1],
|
||||
"C": [3, 1, 2],
|
||||
}
|
||||
)
|
||||
assert smith_set(df) == ["A", "B", "C"]
|
||||
|
||||
|
||||
def test_abpair():
|
||||
df = pl.DataFrame({
|
||||
"A": [1, 2, 1, 3],
|
||||
"B": [2, 1, 3, 1],
|
||||
"C": [3, 3, 2, 2]
|
||||
})
|
||||
assert smith_set(df) == ['A', 'B']
|
||||
df = pl.DataFrame({"A": [1, 2, 1, 3], "B": [2, 1, 3, 1], "C": [3, 3, 2, 2]})
|
||||
assert smith_set(df) == ["A", "B"]
|
||||
|
||||
|
||||
def test_fourcycle():
|
||||
df = pl.DataFrame({
|
||||
"A": [1,2,3,4],
|
||||
"B": [2,3,4,1],
|
||||
"C": [3,4,1,2],
|
||||
"D": [4,1,2,3],
|
||||
})
|
||||
assert smith_set(df) == ['A', 'B', 'C', 'D']
|
||||
df = pl.DataFrame(
|
||||
{
|
||||
"A": [1, 2, 3, 4],
|
||||
"B": [2, 3, 4, 1],
|
||||
"C": [3, 4, 1, 2],
|
||||
"D": [4, 1, 2, 3],
|
||||
}
|
||||
)
|
||||
assert smith_set(df) == ["A", "B", "C", "D"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue