Skip to content

Commit

Permalink
Add isin code for keyed table
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosvm13 committed Jan 22, 2024
1 parent 5f4aa5f commit 29a7207
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions src/pykx/pandas_api/pandas_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,49 +216,48 @@ def isin(self, values):
key_table = 'KeyedTable' in str(type(tab))
key_value = 'KeyedTable' in str(type(values))
n_rows = 0

false_dataframe_f = q("""{u:(cols x);
v:(count[u],count[x])#0b;
flip u!v}""")
if key_value and not key_table:
return q("""{u:(cols x);
v:(count[u],count[x])#0b;
flip u!v}""", tab)

if key_value and key_table:
n_rows, tab, values, kcols = q("""{t:max 0, count[x] -
count u:(key y) inter key x;
(t;x value each u; value y;
key x)}""", tab, values)

return false_dataframe_f(tab)
if key_table:
kcols = q.key(tab)
if key_value:
n_rows, tab = q("""{n_rows:max 0, count[x]-
count rows:(key y) inter key x;
(n_rows;
x each rows)}""", tab, values)
values = q.value(values)
else:
tab = q.value(tab)
dic_value, is_tab = q("""{$[98h = type x;
(flip $[y;value x;x]; 1b);
(x; 0b)]}""", values, key_value)

(flip x; 1b);
(x; 0b)]}""", values)
if key_table and not key_value and is_tab:
return q("""{u:(cols value x);
v:(count[u],count[x])#0b;
(cols kcol) xkey flip (kcol:flip key x),u!v}""", tab)

ftable = q("""{ [table; values; is_tab; n_rows; key_table]
table: $[key_table;value table;table];
flip (cols table)!
{[col_name;tab;values;v_is_tab; n_rows]
col: tab col_name;
ltype: .Q.ty col;
values: $[99h~type values; values col_name; values];
$[v_is_tab or ltype=" ";;
values@:where (lower ltype) = .Q.t abs type each values];
$[0 = count values;
(n_rows + count[col])#0b;
$[v_is_tab;
$[any ltype = (" ";"C");~';=]
[mlen#col;mlen#values],
(n_rows + max 0,count[col]-
mlen: min count[values],
count[col])#0b;
any $[any ltype = (" ";"C");~/:\:;=\:][values;col]
]
]}[;table;values;is_tab; n_rows]
each cols table}""", tab, dic_value, is_tab, n_rows, key_table)
return ftable.set_index(kcols if key_value else q.key(tab)) if key_table else ftable
ftable = false_dataframe_f(tab)
else:
ftable = q("""{ [table; values; is_tab; n_rows]
flip (cols table)!
{[col_name;tab;values;v_is_tab; n_rows]
col: tab col_name;
ltype: .Q.ty col;
values: $[99h~type values; values col_name; values];
$[v_is_tab or ltype=" ";;
values@:where (lower ltype) = .Q.t abs type each values];
$[0 = count values;
(n_rows + count[col])#0b;
$[v_is_tab;
$[any ltype = (" ";"C");~';=]
[mlen#col;mlen#values],
(n_rows + max 0,count[col]-
mlen: min count[values],
count[col])#0b;
any $[any ltype = (" ";"C");~/:\:;=\:][values;col]
]
]}[;table;values;is_tab; n_rows]
each cols table}""", tab, dic_value, is_tab, n_rows)
return ftable.set_index(kcols) if key_table else ftable

@convert_result
def all(self, axis=0, bool_only=False, skipna=True):
Expand Down

0 comments on commit 29a7207

Please sign in to comment.