mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-18 00:45:47 +00:00
corner-case testing for int-preserving mlr top and mlr stats1 percentile
This commit is contained in:
parent
4a7035d775
commit
be05a87f72
4 changed files with 22 additions and 4 deletions
|
|
@ -14,13 +14,15 @@
|
|||
#include "mapping/mappers.h"
|
||||
#include "cli/argparse.h"
|
||||
|
||||
typedef mv_t maybe_sign_flipper_t(mv_t* pval1);
|
||||
|
||||
typedef struct _mapper_top_state_t {
|
||||
slls_t* pvalue_field_names;
|
||||
slls_t* pgroup_by_field_names;
|
||||
int top_count;
|
||||
int show_full_records;
|
||||
int allow_int_float;
|
||||
mv_t sign; // for +1 for max; -1 for min
|
||||
maybe_sign_flipper_t* pmaybe_sign_flipper;
|
||||
lhmslv_t* groups;
|
||||
} mapper_top_state_t;
|
||||
|
||||
|
|
@ -107,7 +109,7 @@ static mapper_t* mapper_top_alloc(slls_t* pvalue_field_names, slls_t* pgroup_by_
|
|||
pstate->show_full_records = show_full_records;
|
||||
pstate->allow_int_float = allow_int_float;
|
||||
pstate->top_count = top_count;
|
||||
pstate->sign = mv_from_int(do_max ? 1 : -1);
|
||||
pstate->pmaybe_sign_flipper = do_max ? n_n_upos_func : n_n_uneg_func;
|
||||
pstate->groups = lhmslv_alloc();
|
||||
|
||||
pmapper->pvstate = pstate;
|
||||
|
|
@ -179,7 +181,7 @@ static void mapper_top_ingest(lrec_t* pinrec, mapper_top_state_t* pstate) {
|
|||
|
||||
// The top-keeper object will free the record if it isn't retained, or
|
||||
// keep it if it is.
|
||||
top_keeper_add(ptop_keeper_for_group, n_nn_times_func(&value_field_nval, &pstate->sign),
|
||||
top_keeper_add(ptop_keeper_for_group, pstate->pmaybe_sign_flipper(&value_field_nval),
|
||||
pstate->show_full_records ? pinrec : NULL);
|
||||
}
|
||||
}
|
||||
|
|
@ -229,7 +231,7 @@ static sllv_t* mapper_top_emit(mapper_top_state_t* pstate, context_t* pctx) {
|
|||
|
||||
char* key = mlr_paste_2_strings(value_field_name, "_top");
|
||||
if (i < ptop_keeper_for_group->size) {
|
||||
mv_t numv = n_nn_times_func(&ptop_keeper_for_group->top_values[i], &pstate->sign);
|
||||
mv_t numv = pstate->pmaybe_sign_flipper(&ptop_keeper_for_group->top_values[i]);
|
||||
char* strv = mv_format_val(&numv);
|
||||
lrec_put(poutrec, key, strv, LREC_FREE_ENTRY_KEY|LREC_FREE_ENTRY_VALUE);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ EXTRA_DIST= \
|
|||
multi-ips.dkvp \
|
||||
multi-sep.csv \
|
||||
multi-sep.dkvp \
|
||||
near-ovf.dkvp \
|
||||
null-fields.csv \
|
||||
null-fields.nidx \
|
||||
null-vs-empty.dkvp \
|
||||
|
|
|
|||
7
c/reg_test/input/near-ovf.dkvp
Normal file
7
c/reg_test/input/near-ovf.dkvp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
x=9223372036854775806,y=-9223372036854775805
|
||||
x=9223372036854775804,y=-9223372036854775804
|
||||
x=9223372036854775801,y=-9223372036854775801
|
||||
x=9223372036854775807,y=-9223372036854775803
|
||||
x=9223372036854775803,y=-9223372036854775807
|
||||
x=9223372036854775802,y=-9223372036854775806
|
||||
x=9223372036854775805,y=-9223372036854775802
|
||||
|
|
@ -166,6 +166,11 @@ run_mlr top -n 1 -f x,y -g a $indir/abixy-wide
|
|||
run_mlr top -a -n 4 -f x $indir/abixy-wide
|
||||
run_mlr top -a -n 4 -f x -g a $indir/abixy-wide
|
||||
|
||||
run_mlr top -n 3 -f x,y $indir/near-ovf.dkvp
|
||||
run_mlr top -n 3 -f x,y --min $indir/near-ovf.dkvp
|
||||
run_mlr top -F -n 3 -f x,y $indir/near-ovf.dkvp
|
||||
run_mlr top -F -n 3 -f x,y --min $indir/near-ovf.dkvp
|
||||
|
||||
run_mlr --seed 12345 sample -k 2 $indir/abixy-het
|
||||
run_mlr --seed 12345 sample -k 2 -g a $indir/abixy-het
|
||||
run_mlr --seed 12345 sample -k 2 -g a,b $indir/abixy-het
|
||||
|
|
@ -326,6 +331,9 @@ run_mlr --oxtab stats1 -s -a mean,sum,count,min,max,mode -f i,x,y -g a,b $indi
|
|||
run_mlr --oxtab stats1 -a mean -f x $indir/abixy-het
|
||||
run_mlr --oxtab stats1 -a mean -f x -g a $indir/abixy-het
|
||||
|
||||
run_mlr --oxtab stats1 -a p0,p50,p100 -f x,y $indir/near-ovf.dkvp
|
||||
run_mlr --oxtab stats1 -a p0,p50,p100 -f x,y -F $indir/near-ovf.dkvp
|
||||
|
||||
run_mlr --opprint stats2 -a linreg-ols,linreg-pca,r2,corr,cov -f x,y,xy,y2 $indir/abixy-wide
|
||||
run_mlr --opprint stats2 -a linreg-ols,linreg-pca,r2,corr,cov -f x,y,xy,y2 -g a,b $indir/abixy-wide
|
||||
run_mlr --oxtab stats2 -s -a linreg-ols,linreg-pca,r2,corr,cov -f x,y,xy,y2 $indir/abixy-wide-short
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue