Skip to content

Commit

Permalink
filter2/mutate2/mutate3: fix a bug of mismatch between column names a…
Browse files Browse the repository at this point in the history
…nd values. #295
  • Loading branch information
shenwei356 committed Dec 2, 2024
1 parent d60bf11 commit b6d6456
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
- [csvtk v0.31.2](https://github.com/shenwei356/csvtk/releases/tag/v0.31.2)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/csvtk/v0.31.2/total.svg)](https://github.com/shenwei356/csvtk/releases/tag/v0.31.2)
- `csvtk filter2/mutate2/mutate3`:
- fix a bug of mismatch between column names and values. [#295](https://github.com/shenwei356/csvtk/issues/295)
- [csvtk v0.31.1](https://github.com/shenwei356/csvtk/releases/tag/v0.31.1)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/csvtk/v0.31.1/total.svg)](https://github.com/shenwei356/csvtk/releases/tag/v0.31.1)
- `csvtk filter2/mutate2/mutate3`:
Expand Down
6 changes: 1 addition & 5 deletions csvtk/cmd/filter2.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ Custom functions:
var valueFloat float64
var colnames2fileds map[string][]int // column name -> []field
var colnamesMap map[string]*regexp.Regexp
var fieldsUniq []int

var selectWithColnames bool

Expand All @@ -249,8 +248,6 @@ Custom functions:
parameters2 = make(map[string]interface{}, len(record.All))
parameters2["shenweiNULL"] = nil

fieldsUniq = UniqInts(record.Fields)

if !config.NoHeaderRow || record.IsHeaderRow { // do not replace head line
colnames2fileds = make(map[string][]int, len(record.Selected))

Expand All @@ -261,7 +258,6 @@ Custom functions:
} else {
colnames2fileds[col] = append(colnames2fileds[col], record.Fields[i])
}

colnamesMap[col] = fuzzyField2Regexp(col)
}

Expand All @@ -280,7 +276,7 @@ Custom functions:

// prepaire parameters
if !selectWithColnames {
for _, fieldTmp = range fieldsUniq {
for _, fieldTmp = range record.Fields {
value = record.All[fieldTmp-1]
col = strconv.Itoa(fieldTmp)
if varType[col] == 1 {
Expand Down
5 changes: 1 addition & 4 deletions csvtk/cmd/mutate2.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ Custom functions:
var result interface{}
var colnames2fileds map[string][]int // column name -> []field
var colnamesMap map[string]*regexp.Regexp
var fieldsUniq []int
var selectWithColnames bool
var record2 []string // for output
keys := make([]string, 0, 8)
Expand All @@ -259,8 +258,6 @@ Custom functions:
parameters2 = make(map[string]interface{}, len(record.All))
parameters2["shenweiNULL"] = nil

fieldsUniq = UniqInts(record.Fields)

if !config.NoHeaderRow || record.IsHeaderRow { // do not replace head line
colnames2fileds = make(map[string][]int, len(record.Selected))

Expand Down Expand Up @@ -310,7 +307,7 @@ Custom functions:

// prepare parameters
if !selectWithColnames {
for _, fieldTmp = range fieldsUniq {
for _, fieldTmp = range record.Fields {
value = record.All[fieldTmp-1]
col = strconv.Itoa(fieldTmp)
if varType[col] == 1 {
Expand Down
5 changes: 1 addition & 4 deletions csvtk/cmd/mutate3.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ func doMutate3(config Config, opts mutate3Opts) {
var result interface{}
var colnames2fileds map[string][]int // column name -> []field
var colnamesMap map[string]*regexp.Regexp
var fieldsUniq []int
var selectWithColnames bool
var record2 []string // for output
keys := make([]string, 0, 8)
Expand All @@ -264,8 +263,6 @@ func doMutate3(config Config, opts mutate3Opts) {
parameters2 = make(map[string]interface{}, len(record.All))
parameters2["shenweiNULL"] = nil

fieldsUniq = UniqInts(record.Fields)

if !config.NoHeaderRow || record.IsHeaderRow { // do not replace head line
colnames2fileds = make(map[string][]int, len(record.Selected))

Expand Down Expand Up @@ -315,7 +312,7 @@ func doMutate3(config Config, opts mutate3Opts) {

// prepare parameters
if !selectWithColnames {
for _, fieldTmp = range fieldsUniq {
for _, fieldTmp = range record.Fields {
value = record.All[fieldTmp-1]
col = strconv.Itoa(fieldTmp)
if varType[col] == 1 {
Expand Down
2 changes: 2 additions & 0 deletions csvtk/example.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
strain B A
GCA_000149305.1 0 77.7364887

0 comments on commit b6d6456

Please sign in to comment.