-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor q code. pflake8 fixes. #31
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -453,12 +453,14 @@ def rename(self, labels=None, index=None, columns=None, axis=0, | |
t = _rename_columns(t, columns) | ||
|
||
return t | ||
|
||
def add_suffix(self, suffix, axis=0): | ||
t = self | ||
if axis == 1: | ||
c_str = 'cols value' if "Keyed" in str(type(t)) else 'cols' | ||
t = q(f'{{(c!`$string[c:{c_str} y],\:string x)xcol y}}', suffix, t) | ||
t = q('''{[s;t] | ||
c:$[99h~type t;cols value@;cols] t; | ||
(c!`$string[c],\\:string s) xcol t | ||
}''', suffix, t) | ||
elif axis == 0: | ||
raise ValueError('nyi') | ||
else: | ||
|
@@ -468,8 +470,10 @@ def add_suffix(self, suffix, axis=0): | |
def add_prefix(self, prefix, axis=0): | ||
t = self | ||
if axis == 1: | ||
c_str = 'cols value' if "Keyed" in str(type(t)) else 'cols' | ||
t = q(f'{{(c!`$string[x],/:string c:{c_str} y)xcol y}}', prefix, t) | ||
t = q('''{[s;t] | ||
c:$[99h~type t;cols value@;cols] t; | ||
(c!`$string[s],/:string[c]) xcol t | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I agree - I missed that |
||
}''', prefix, t) | ||
elif axis == 0: | ||
raise ValueError('nyi') | ||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,21 +162,19 @@ def std(self, axis: int = 0, ddof: int = 1, numeric_only: bool = False): | |
if numeric_only: | ||
tab = _get_numeric_only_subtable(tab) | ||
|
||
key_str = '' if axis == 0 else '`$string ' | ||
val_str = '' if axis == 0 else '"f"$value ' | ||
query_str = 'cols[tab]' if axis == 0 else 'til[count[tab]]' | ||
where_str = ' where not (::)~/:r[;1]' | ||
x_dev_str = f'{{avg sqrt (sum xexp[x-avg x;2]) % count[x]-{ddof}}}' | ||
dev_str = 'dev' if ddof == 0 else 'sdev' if ddof == 1 else x_dev_str | ||
axis_keys = q('{[axis;tab] $[0~axis;cols;`$string til count @] tab}', axis, tab) | ||
|
||
if ddof == len(tab): | ||
return q(f'{{[tab]{query_str}!count[{query_str}]#0n}}', tab) | ||
return q('{x!count[x]#0n}', axis_keys) | ||
|
||
return q( | ||
'{[tab]' | ||
f'r:{{[tab; x] ({key_str}x; {dev_str} {val_str}tab[x])}}[tab;] each {query_str};' | ||
f'(,/) {{(enlist x 0)!(enlist x 1)}} each r{where_str}}}', | ||
tab | ||
'''{[tab;axis;ddof;axis_keys] | ||
tab:$[0~axis;(::);flip] value flip tab; | ||
d:$[0~ddof;dev; | ||
1~ddof;sdev; | ||
{[ddof;x] avg sqrt (sum xexp[x-avg x;2]) % count[x]-ddof}ddof]; | ||
axis_keys!d each tab | ||
}''', tab, axis, ddof, axis_keys | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
) | ||
|
||
@api_return | ||
|
@@ -274,13 +272,11 @@ def prod(self, axis=0, skipna=True, numeric_only=False, min_count=0): | |
def skew(self, axis=0, skipna=True, numeric_only=False): | ||
res, cols = preparse_computations(self, axis, skipna, numeric_only) | ||
return (q( | ||
'{[row]' | ||
# adjusted Fisher-Pearson standardized moment | ||
'm:{(sum (x - avg x) xexp y) % count x};' | ||
'g1:{[m;x]m:m[x]; m[3] % m[2] xexp 3%2}[m];' | ||
'{[g1;x]g1[x] * sqrt[n * n-1] % neg[2] + n:count x}[g1] each row}', | ||
res | ||
), cols) | ||
'''{[row] | ||
m:{(sum (x - avg x) xexp y) % count x}; | ||
g1:{[m;x]m:m[x]; m[3] % m[2] xexp 3%2}[m]; | ||
(g1 each row) * {sqrt[n * n-1] % neg[2] + n:count x} each row | ||
}''', res), cols) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
@convert_result | ||
def sum(self, axis=0, skipna=True, numeric_only=False, min_count=0): | ||
|
@@ -352,4 +348,4 @@ def agg(self, func, axis=0, *args, **kwargs): # noqa: C901 | |
@convert_result | ||
def count(self, axis=0, numeric_only=False): | ||
res, cols = preparse_computations(self, axis, True, numeric_only) | ||
return (q('count each', res), cols) | ||
return (q('count each', res), cols) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍