Skip to content
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

Series & Dataframe append/insert at a given position #109

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: go
go: master
before_script:
- echo 'Checking code quality issues.'
- go vet ./...
- echo 'Checking that gofmt was used.'
- diff -u <(echo -n) <(gofmt -d .)
- echo 'Checking tidiness of go mod.'
- go mod tidy
- test -z "$(git status --porcelain)"
script:
- echo 'Running tests.'
- go test -v ./...
61 changes: 59 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,71 @@ column "B" is greater than 4:
fil := df.Filter(
dataframe.F{"A", series.Eq, "a"},
dataframe.F{"B", series.Greater, 4},
)

filAlt := df.FilterAggregation(
dataframe.Or,
dataframe.F{"A", series.Eq, "a"},
dataframe.F{"B", series.Greater, 4},
)
```

Filters inside Filter are combined as OR operations, alternatively we can use `df.FilterAggragation` with `dataframe.Or`.

If we want to combine filters with AND operations, we can use `df.FilterAggregation` with `dataframe.And`.

```go
fil := df.FilterAggregation(
dataframe.And,
dataframe.F{"A", series.Eq, "a"},
dataframe.F{"D", series.Eq, true},
)
```

To combine AND and OR operations, we can use chaining of filters.

```go
// combine filters with OR
fil := df.Filter(
dataframe.F{"A", series.Eq, "a"},
dataframe.F{"B", series.Greater, 4},
)
// apply AND for fil and fil2
fil2 := fil.Filter(
dataframe.F{"D", series.Eq, true},
)
```

Filters inside Filter are combined as OR operations whereas if we chain
Filter methods, they will behave as AND.
Filtering is based on predefined comparison operators:
* `series.Eq`
* `series.Neq`
* `series.Greater`
* `series.GreaterEq`
* `series.Less`
* `series.LessEq`
* `series.In`

However, if these filter operations are not sufficient, we can use user-defined comparators.
We use `series.CompFunc` and a user-defined function with the signature `func(series.Element) bool` to provide user-defined filters to `df.Filter` and `df.FilterAggregation`.

```go
hasPrefix := func(prefix string) func(el series.Element) bool {
return func (el series.Element) bool {
if el.Type() == String {
if val, ok := el.Val().(string); ok {
return strings.HasPrefix(val, prefix)
}
}
return false
}
}

fil := df.Filter(
dataframe.F{"A", series.CompFunc, hasPrefix("aa")},
)
```

This example filters rows based on whether they have a cell value starting with `"aa"` in column `"A"`.

#### Arrange

Expand Down
Loading