-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed error with then method - fixes #64
- Loading branch information
Showing
9 changed files
with
253 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
module Polars | ||
# @private | ||
class When | ||
attr_accessor :_when | ||
|
||
def initialize(rbwhen) | ||
self._when = rbwhen | ||
end | ||
|
||
def then(statement) | ||
statement_rbexpr = Utils.parse_as_expression(statement) | ||
Then.new(_when.then(statement_rbexpr)) | ||
end | ||
end | ||
|
||
# @private | ||
class Then < Expr | ||
attr_accessor :_then | ||
|
||
def initialize(rbthen) | ||
self._then = rbthen | ||
end | ||
|
||
def self._from_rbexpr(rbexpr) | ||
Utils.wrap_expr(rbexpr) | ||
end | ||
|
||
def _rbexpr | ||
_then.otherwise(Polars.lit(nil)._rbexpr) | ||
end | ||
|
||
def when(*predicates, **constraints) | ||
condition_rbexpr = Utils.parse_when_inputs(*predicates, **constraints) | ||
ChainedWhen.new(_then.when(condition_rbexpr)) | ||
end | ||
|
||
def otherwise(statement) | ||
statement_rbexpr = Utils.parse_as_expression(statement) | ||
Utils.wrap_expr(_then.otherwise(statement_rbexpr)) | ||
end | ||
end | ||
|
||
# @private | ||
class ChainedWhen | ||
attr_accessor :_chained_when | ||
|
||
def initialize(chained_when) | ||
self._chained_when = chained_when | ||
end | ||
|
||
def then(statement) | ||
statement_rbexpr = Utils.parse_as_expression(statement) | ||
ChainedThen.new(_chained_when.then(statement_rbexpr)) | ||
end | ||
end | ||
|
||
# @private | ||
class ChainedThen < Expr | ||
attr_accessor :_chained_then | ||
|
||
def initialize(chained_then) | ||
self._chained_then = chained_then | ||
end | ||
|
||
def self._from_rbexpr(rbexpr) | ||
Utils.wrap_expr(rbexpr) | ||
end | ||
|
||
def _rbexpr | ||
_chained_then.otherwise(Polars.lit(nil)._rbexpr) | ||
end | ||
|
||
def when(*predicates, **constraints) | ||
condition_rbexpr = Utils.parse_when_inputs(*predicates, **constraints) | ||
ChainedWhen.new(_chained_then.when(condition_rbexpr)) | ||
end | ||
|
||
def otherwise(statement) | ||
statement_rbexpr = Utils.parse_as_expression(statement) | ||
Utils.wrap_expr(_chained_then.otherwise(statement_rbexpr)) | ||
end | ||
end | ||
end |