Skip to content

Commit 5ff9415

Browse files
cmccarthy1dmorgankxDianeod
authored
Update to drop-constant (#77)
* Handling of null datetimes in pandas dataframes, pandas > 1.0 now default for support * removal of error trap * Minor change to structure of dt_convert * unneccesary conversion to timestamp * wording update * addition of missing xval folder from releases * updated ksdistrib to correspond with scipy * update to drop constant function to handle non numeric data and highlight errors * dropconstant refactor * optimisation to dropconstant function Co-authored-by: dmorgankx <44678213+dmorgankx@users.noreply.github.com> Co-authored-by: Deanna Morgan <dmorgan1@kx.com> Co-authored-by: Dianeod <40861871+Dianeod@users.noreply.github.com> Co-authored-by: Dianeod <dodonoghue@kx.com>
1 parent d69657c commit 5ff9415

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

util/preproc.q

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
\d .ml
22

33
/ data preprocessing
4-
dropconstant:{f(where 0=0^var each k)_k:(f:$[tp:99=type x;;flip])x}
4+
5+
/* x = simple table/dictionary
6+
dropconstant:{
7+
if[not(typ:type x)in 98 99h;'"Data must be simple table or dictionary"];
8+
if[99h=typ;if[98h~type value x;'"Data cannot be a keyed table"]];
9+
// find keys/cols that contain non-numeric data
10+
fc:$[typ=99h;i.fndkey;i.fndcols].(x;"csg ",upper .Q.t);
11+
// store instructions to flip table and execute this
12+
dt:(fdata:$[99=typ;;flip])x;
13+
// drop constant numeric and non numeric cols/keys
14+
fdata i.dropconst.num[fc _ dt],i.dropconst.other fc#dt
15+
}
16+
17+
// logic to find numeric and drop constant columns
18+
i.dropconst.num:{(where 0=0^var each x)_x}
19+
i.dropconst.other:{(where{all 1_(~':)x}each x)_x}
20+
// Find keys relating to a specific type
21+
i.fndkey:{where({.Q.t abs type x}each x)in y}
22+
23+
524
minmaxscaler:i.ap{(x-mnx)%max[x]-mnx:min x}
625
stdscaler :i.ap{(x-avg x)%dev x}
726
/ replace +/- 0w with max/min vals
@@ -50,4 +69,4 @@ i.timesplit[`p`z]:{raze i.timesplit[`d`n]@\:x}
5069
i.timesplit1:{i.timesplit[`$.Q.t type x]x:raze x}
5170
timesplit:{[x;c]
5271
if[(::)~c;c:i.fndcols[x;"dmntvupz"]];
53-
flip(c _ flip x),raze{(`$"_"sv'string y,'key r)!value r:i.timesplit1 x y}/:[x]c,:()}
72+
flip(c _ flip x),raze{(`$"_"sv'string y,'key r)!value r:i.timesplit1 x y}/:[x]c,:()}

0 commit comments

Comments
 (0)