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

Initial offset design ideas #12015

Draft
wants to merge 54 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
eb37ef5
Initial offset design ideas
AdRiley Jan 7, 2025
7989ce8
Offset Column design work
AdRiley Jan 9, 2025
b0bf1c8
Table design
AdRiley Jan 9, 2025
d8740d2
Start to add test framework
AdRiley Jan 9, 2025
1cd2aa6
Add set_mode
AdRiley Jan 9, 2025
5130f56
Green
AdRiley Jan 10, 2025
bd3768a
More tests
AdRiley Jan 10, 2025
cdffb5d
One more test
AdRiley Jan 10, 2025
b490f0a
Table.offset Red
AdRiley Jan 10, 2025
a74f5fa
Plumbing
AdRiley Jan 10, 2025
ee45c92
More plumbing
AdRiley Jan 10, 2025
da5ec3f
First table test green
AdRiley Jan 10, 2025
089cf05
Next green table test
AdRiley Jan 10, 2025
af95bdc
Next table tests
AdRiley Jan 10, 2025
0d2933f
Green
AdRiley Jan 13, 2025
b331d7d
Red
AdRiley Jan 13, 2025
937f851
Green using mask solution
AdRiley Jan 13, 2025
d01bd24
Refactor
AdRiley Jan 13, 2025
a811df6
refactor
AdRiley Jan 13, 2025
8a97331
Refactor
AdRiley Jan 13, 2025
5d44c4d
More green tests
AdRiley Jan 13, 2025
09664f0
Red
AdRiley Jan 13, 2025
7c41b53
Green
AdRiley Jan 13, 2025
ccfb97c
Refactor
AdRiley Jan 13, 2025
68181ad
Green
AdRiley Jan 13, 2025
1cda931
Red
AdRiley Jan 14, 2025
c1e663a
Green
AdRiley Jan 14, 2025
5b9f789
Green
AdRiley Jan 14, 2025
1119796
Green
AdRiley Jan 14, 2025
c999528
Red
AdRiley Jan 14, 2025
7a2fa9e
Green
AdRiley Jan 14, 2025
4afadeb
Ordering and closet fill
AdRiley Jan 14, 2025
7a60ce6
Green
AdRiley Jan 14, 2025
14ca426
Refactor
AdRiley Jan 14, 2025
b6acd89
Refactor
AdRiley Jan 14, 2025
74d80a8
Refactor
AdRiley Jan 14, 2025
64dde8a
Cleanup
AdRiley Jan 14, 2025
6de5c51
Refactor
AdRiley Jan 15, 2025
9309586
Documentaion
AdRiley Jan 15, 2025
c50fef4
Column Names
AdRiley Jan 15, 2025
f928e1e
Multiple columns
AdRiley Jan 16, 2025
1b37fa6
Refactor
AdRiley Jan 16, 2025
134b818
Refactor
AdRiley Jan 16, 2025
67f9137
Refactor
AdRiley Jan 16, 2025
b9c69e2
Refactor
AdRiley Jan 16, 2025
791740a
Refactor
AdRiley Jan 16, 2025
8df3f4c
set_mode=update
AdRiley Jan 16, 2025
1dd496d
More tests
AdRiley Jan 17, 2025
88a8063
Remove on_problems
AdRiley Jan 17, 2025
b572fde
Rename to Fill_With
AdRiley Jan 17, 2025
6a37f2d
Documentation
AdRiley Jan 17, 2025
1eeff6f
Revert "Remove on_problems"
AdRiley Jan 17, 2025
3d5c77d
fmt
AdRiley Jan 17, 2025
7819762
New alias
AdRiley Jan 17, 2025
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
Prev Previous commit
Next Next commit
Green
  • Loading branch information
AdRiley committed Jan 17, 2025
commit 5130f562c54f02f33e5f0a35cec2cc07fbd80b19
25 changes: 13 additions & 12 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso
Original file line number Diff line number Diff line change
Expand Up @@ -2633,18 +2633,19 @@ type Column
@default (self-> Widget_Helpers.make_fill_default_value_selector2 value_types=self.value_type)
offset : Integer -> Column | Previous_Value | Any -> Column
offset self n=-1:Integer default:OffFill=..Nothing -> Column =
as_vector = self.to_vector
fill_vector = case default of
OffFill.Nothing -> Vector.fill n.abs Nothing
OffFill.Closest_Value -> if n<0 then Vector.fill n.abs (as_vector.at 0) else Vector.fill n.abs (as_vector.at (self.length-1))
OffFill.Wrap_Around -> if n<0 then as_vector.take (..Last n.abs) else as_vector.take (..First n)
OffFill.Constant constant -> Vector.fill n.abs constant

offset_vector = if n > 0 then as_vector + fill_vector else
fill_vector + as_vector
resized_vector = if n > 0 then offset_vector.take (..Last self.length) else
offset_vector.take (..First self.length)
Column.from_vector self.name resized_vector
if self.length == 0 then self else
as_vector = self.to_vector
fill_vector = case default of
OffFill.Nothing -> Vector.fill n.abs Nothing
OffFill.Closest_Value -> if n<0 then Vector.fill n.abs (as_vector.at 0) else Vector.fill n.abs (as_vector.at (self.length-1))
OffFill.Wrap_Around -> if n<0 then as_vector.take (..Last n.abs) else as_vector.take (..First n)
OffFill.Constant constant -> Vector.fill n.abs constant

offset_vector = if n > 0 then as_vector + fill_vector else
fill_vector + as_vector
resized_vector = if n > 0 then offset_vector.take (..Last self.length) else
offset_vector.take (..First self.length)
Column.from_vector self.name resized_vector

## PRIVATE
pretty : Text
Expand Down
58 changes: 56 additions & 2 deletions test/Table_Tests/src/Common_Table_Operations/Offset_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ from Standard.Test import all
from Standard.Database.Errors import Unsupported_Database_Operation
import Standard.Database.Feature.Feature

from project.Common_Table_Operations.Util import run_default_backend
import project.Common_Table_Operations.Util

main filter=Nothing = run_default_backend add_specs filter

add_specs suite_builder setup =
Expand All @@ -18,6 +21,57 @@ add_specs suite_builder setup =
c2 = c.offset
c2.should_fail_with (Unsupported_Database_Operation.Error "offset")

add_filter_specs suite_builder setup =
add_offset_specs suite_builder setup =
prefix = setup.prefix
table_builder = setup.light_table_builder
build_sorted_table = Util.build_sorted_table setup
t = build_sorted_table [["A", [1, 2, 3]], ["B", [Nothing, Nothing, Nothing]]]
c = t.at 0
c_nothings = t.at 1
c_zero_rows = t.take 0 . at 0
suite_builder.group prefix+"Column.Offset with default fill strategy" group_builder->
group_builder.specify "Works with default values" <|
r = c.offset
r.to_vector . should_equal [Nothing, 1, 2]
group_builder.specify "Negative n shifts the values down" <|
r = c.offset -1
r.to_vector . should_equal [Nothing, 1, 2]
group_builder.specify "Positive n shifts the values up" <|
r = c.offset 1
r.to_vector . should_equal [2, 3, Nothing]
group_builder.specify "Zero n is a no-op" <|
r = c.offset 0
r.to_vector . should_equal [1, 2, 3]
group_builder.specify "Large negative n values work" <|
r = c.offset -1024
r.to_vector . should_equal [Nothing, Nothing, Nothing]
group_builder.specify "Large positive n values work" <|
r = c.offset 1024
r.to_vector . should_equal [Nothing, Nothing, Nothing]
group_builder.specify "Works with zero rows" <|
r = c_zero_rows.offset
r.to_vector . should_equal []
suite_builder.group prefix+"Column.Offset with closest value fill strategy" group_builder->
group_builder.specify "Negative n shifts the values down" <|
r = c.offset -1 ..Closest_Value
r.to_vector . should_equal [1, 1, 2]
group_builder.specify "Positive n shifts the values up" <|
r = c.offset 1 ..Closest_Value
r.to_vector . should_equal [2, 3, 3]
group_builder.specify "Zero n is a no-op" <|
r = c.offset 0 ..Closest_Value
r.to_vector . should_equal [1, 2, 3]
group_builder.specify "Large negative n values work" <|
r = c.offset -1024 ..Closest_Value
r.to_vector . should_equal [1, 1, 1]
group_builder.specify "Large positive n values work" <|
r = c.offset 1024 ..Closest_Value
r.to_vector . should_equal [3, 3, 3]
group_builder.specify "Works with zero rows" <|
r = c_zero_rows.offset -1 ..Closest_Value
r.to_vector . should_equal []
group_builder.specify "Works with negative n and column of nothings" <|
r = c_nothings.offset -1 ..Closest_Value
r.to_vector . should_equal [Nothing, Nothing, Nothing]
group_builder.specify "Works with positive n and column of nothings" <|
r = c_nothings.offset 1 ..Closest_Value
r.to_vector . should_equal [Nothing, Nothing, Nothing]