Repository: jtablesaw/tablesaw
Pull request #539 (2019-06-18 20:50:28)

Add fillWith(double)
Thanks for contributing.

- [X] Tick to sign-off your agreement to the [Developer Certificate of Origin (DCO) 1.1](https://developercertificate.org)

## Description

Now you can do `fillWith(1.0)` instead of `fillWith(() -> 1.0)`

## Testing

Added a unit test


lwhite1: i see the need for fillWith(double), but is the supplier version not also sometimes useful? IDK, like if you wanted to fill with random numbers, or a sequence of some kind. 
benmccann: Great point! I hadn't been able to think of a usecase, but that's a good example. I've added it back
lwhite1: LGTM

Patch:
diff --git a/core/src/main/java/tech/tablesaw/api/DoubleColumn.java b/core/src/main/java/tech/tablesaw/api/DoubleColumn.java
index 67f0b062..dcdcc540 100644
--- a/core/src/main/java/tech/tablesaw/api/DoubleColumn.java
+++ b/core/src/main/java/tech/tablesaw/api/DoubleColumn.java
@@ -482,6 +482,14 @@ public class DoubleColumn extends NumberColumn<Double> implements NumberFillers<
         return this;
     }
 
+    @Override
+    public DoubleColumn fillWith(double d) {
+        for (int r = 0; r < size(); r++) {
+            set(r, d);
+        }
+        return this;
+    }
+
     @Override
     public DoubleColumn inRange(int start, int end) {
         return (DoubleColumn) super.inRange(start, end);
diff --git a/core/src/main/java/tech/tablesaw/api/Table.java b/core/src/main/java/tech/tablesaw/api/Table.java
index 67ffc791..d3de7bd2 100644
--- a/core/src/main/java/tech/tablesaw/api/Table.java
+++ b/core/src/main/java/tech/tablesaw/api/Table.java
@@ -464,7 +464,7 @@ public class Table extends Relation implements Iterable<Row> {
      * @return An array two tables, with the first table having the proportion specified in the method parameter,
      * and the second table having the balance of the rows
      */
-    public Table[] stratifiedSampleSplit(CategoricalColumn column, double table1Proportion) {
+    public Table[] stratifiedSampleSplit(CategoricalColumn<?> column, double table1Proportion) {
         Preconditions.checkArgument(containsColumn(column),
                 "The categorical column must be part of the table, you can create a string column and add it to this table before sampling.");
         final Table first = emptyCopy();
diff --git a/core/src/main/java/tech/tablesaw/columns/numbers/NumberFillers.java b/core/src/main/java/tech/tablesaw/columns/numbers/NumberFillers.java
index 7ec44b31..66bc3dc6 100644
--- a/core/src/main/java/tech/tablesaw/columns/numbers/NumberFillers.java
+++ b/core/src/main/java/tech/tablesaw/columns/numbers/NumberFillers.java
@@ -26,4 +26,6 @@ public interface NumberFillers<T> {
     T fillWith(DoubleRangeIterable iterable);
 
     T fillWith(final DoubleSupplier supplier);
+
+    T fillWith(double d);
 }


Test patch:
diff --git a/core/src/test/java/tech/tablesaw/columns/numbers/NumberFillersTest.java b/core/src/test/java/tech/tablesaw/columns/numbers/NumberFillersTest.java
index f289fc9e..71d2a83b 100644
--- a/core/src/test/java/tech/tablesaw/columns/numbers/NumberFillersTest.java
+++ b/core/src/test/java/tech/tablesaw/columns/numbers/NumberFillersTest.java
@@ -17,6 +17,11 @@ public class NumberFillersTest {
         assertEquals(expected.length, num);
     }
 
+    @Test
+    public void fillWithDouble() {
+        assertContentEquals(create("doubles", new double[5]).fillWith(1.0), 1.0, 1.0, 1.0, 1.0, 1.0);
+    }
+    
     @Test
     public void testFromToBy() {
         assertContentEquals(create("doubles", new double[5]).fillWith(range(1.0, 12.0, 2.5)), 1.0, 3.5, 6.0, 8.5, 11.0);