Skip to content

Commit

Permalink
parse_to_columns should generate at least one row for a non-match (#7171
Browse files Browse the repository at this point in the history
)
  • Loading branch information
GregoryTravis authored Jun 30, 2023
1 parent 550d146 commit c866aa7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ parse_to_columns table input_column_id pattern="." case_sensitivity=Case_Sensiti
column = table.at input_column_id

new_table = Value_Type.expect_text column <|
fan_out_to_rows_and_columns table input_column_id fun column_names on_problems=on_problems
fan_out_to_rows_and_columns table input_column_id fun column_names at_least_one_row=True on_problems=on_problems
if parse_values then new_table.parse on_problems=on_problems else new_table

## PRIVATE
Expand Down
13 changes: 9 additions & 4 deletions test/Table_Tests/src/In_Memory/Split_Tokenize_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,25 @@ spec =
actual.should_equal expected

Test.specify "input with no matches" <|
t = Table.from_rows ["foo", "bar", "baz"] [["x", "a", "y"]]
expected = Table.from_rows ["foo", "bar", "baz"] []
t = Table.from_rows ["foo", "bar", "baz"] [["x", "a", "y"], ["xx", "q12", "yy"], ["xxx", "34r", "yyyy"]]
expected = Table.from_rows ["foo", "bar", "baz"] [["x", Nothing, "y"], ["xx", 12, "yy"], ["xxx", 34, "yyyy"]]
actual = t.parse_to_columns "bar" "\d+"
actual.should_equal expected

t2 = Table.new [["amount", ["$1.23B", "$1.3M", "$2.32M $3.43B", "None"]]]
expected2 = Table.from_rows ["Raised", "Scale"] [[1.23, "B"], [1.3, "M"], [2.32, "M"], [3.43, "B"], [Nothing, Nothing]]
actual2 = t2.parse_to_columns "amount" "\$(?<Raised>\d+(?:.\d+)?)(?<Scale>B|M)"
actual2.should_equal expected2

Test.specify "input with no matches, with regex groups" <|
t = Table.from_rows ["foo", "bar", "baz"] [["x", "a", "y"]]
expected = Table.from_rows ["foo", "bar 1", "bar 2", "baz"] []
expected = Table.from_rows ["foo", "bar 1", "bar 2", "baz"] [["x", Nothing, Nothing, "y"]]
actual = t.parse_to_columns "bar" "(\d)(\d)"
actual.should_equal expected

Test.specify "input with no matches, with named and unnamed regex groups" <|
t = Table.from_rows ["foo", "bar", "baz"] [["x", "a", "y"]]
expected = Table.from_rows ["foo", "quux", "bar 1", "foo 1", "bar 2", "baz"] []
expected = Table.from_rows ["foo", "quux", "bar 1", "foo 1", "bar 2", "baz"] [["x", Nothing, Nothing, Nothing, Nothing, "y"]]
actual = t.parse_to_columns "bar" "(?<quux>)(\d)(?<foo>\d)(\d)"
actual.should_equal expected

Expand Down

0 comments on commit c866aa7

Please sign in to comment.