Repository: jtablesaw/tablesaw
Pull request #999 (2021-09-30 03:33:00)

Minor extensions
Thanks for contributing.

- [x] Tick to sign-off your agreement to the [Developer Certificate of Origin (DCO) 1.1](https://developercertificate.org)

## Description

What was changed
minor extensions to table and common APIs

## Testing

Did you add a unit test?
yes.


Patch:
diff --git a/core/src/main/java/tech/tablesaw/api/DoubleColumn.java b/core/src/main/java/tech/tablesaw/api/DoubleColumn.java
index 7586fece..ce2baab1 100644
--- a/core/src/main/java/tech/tablesaw/api/DoubleColumn.java
+++ b/core/src/main/java/tech/tablesaw/api/DoubleColumn.java
@@ -283,6 +283,10 @@ public class DoubleColumn extends NumberColumn<DoubleColumn, Double>
     return data.iterator();
   }
 
+  public double[] asDoubleArray() {
+    return data.toDoubleArray();
+  }
+
   @Override
   public Double[] asObjectArray() {
     final Double[] output = new Double[size()];
diff --git a/core/src/main/java/tech/tablesaw/api/FloatColumn.java b/core/src/main/java/tech/tablesaw/api/FloatColumn.java
index 2848fcd9..57f9d662 100644
--- a/core/src/main/java/tech/tablesaw/api/FloatColumn.java
+++ b/core/src/main/java/tech/tablesaw/api/FloatColumn.java
@@ -206,6 +206,10 @@ public class FloatColumn extends NumberColumn<FloatColumn, Float> {
     return data.iterator();
   }
 
+  public float[] asFloatArray() {
+    return data.toFloatArray();
+  }
+
   @Override
   public Float[] asObjectArray() {
     final Float[] output = new Float[size()];
diff --git a/core/src/main/java/tech/tablesaw/api/IntColumn.java b/core/src/main/java/tech/tablesaw/api/IntColumn.java
index f1949061..f3c269ab 100644
--- a/core/src/main/java/tech/tablesaw/api/IntColumn.java
+++ b/core/src/main/java/tech/tablesaw/api/IntColumn.java
@@ -99,6 +99,10 @@ public class IntColumn extends NumberColumn<IntColumn, Integer>
     return isMissingValue(result) ? null : result;
   }
 
+  public int[] asIntArray() {
+    return data.toIntArray();
+  }
+
   @Override
   public IntColumn subset(final int[] rows) {
     final IntColumn c = this.emptyCopy();
@@ -444,6 +448,13 @@ public class IntColumn extends NumberColumn<IntColumn, Integer>
     return results;
   }
 
+  public Selection isNotIn(final IntColumn ints) {
+    final Selection results = new BitmapBackedSelection();
+    results.addRange(0, size());
+    results.andNot(isIn(ints.data.toIntArray()));
+    return results;
+  }
+
   /**
    * Returns a new DoubleColumn containing a value for each value in this column, truncating if
    * necessary.
diff --git a/core/src/main/java/tech/tablesaw/api/ShortColumn.java b/core/src/main/java/tech/tablesaw/api/ShortColumn.java
index 8e98d4c6..df4d3daa 100644
--- a/core/src/main/java/tech/tablesaw/api/ShortColumn.java
+++ b/core/src/main/java/tech/tablesaw/api/ShortColumn.java
@@ -234,6 +234,10 @@ public class ShortColumn extends NumberColumn<ShortColumn, Short>
     return output;
   }
 
+  public short[] asShortArray() {
+    return data.toShortArray();
+  }
+
   @Override
   public int compare(Short o1, Short o2) {
     return Short.compare(o1, o2);
diff --git a/core/src/main/java/tech/tablesaw/api/Table.java b/core/src/main/java/tech/tablesaw/api/Table.java
index db05e279..1b5eefab 100644
--- a/core/src/main/java/tech/tablesaw/api/Table.java
+++ b/core/src/main/java/tech/tablesaw/api/Table.java
@@ -909,7 +909,7 @@ public class Table extends Relation implements Iterable<Row> {
   }
 
   @SuppressWarnings({"rawtypes", "unchecked"})
-  public Table append(Table tableToAppend) {
+  public Table append(Relation tableToAppend) {
     for (final Column column : columnList) {
       final Column columnToAppend = tableToAppend.column(column.name());
       column.append(columnToAppend);
diff --git a/core/src/main/java/tech/tablesaw/columns/strings/StringFilters.java b/core/src/main/java/tech/tablesaw/columns/strings/StringFilters.java
index f7520cca..44fae1ac 100644
--- a/core/src/main/java/tech/tablesaw/columns/strings/StringFilters.java
+++ b/core/src/main/java/tech/tablesaw/columns/strings/StringFilters.java
@@ -143,6 +143,14 @@ public interface StringFilters extends Column<String>, StringFilterSpec<Selectio
 
   Selection isIn(Collection<String> strings);
 
+  default Selection isIn(Column<String> strings) {
+    return isIn(strings.unique().asList());
+  }
+
+  default Selection isNotIn(Column<String> strings) {
+    return isNotIn(strings.unique().asList());
+  }
+
   Selection isNotIn(String... strings);
 
   Selection isNotIn(Collection<String> strings);


Test patch:
diff --git a/core/src/test/java/tech/tablesaw/api/StringColumnTest.java b/core/src/test/java/tech/tablesaw/api/StringColumnTest.java
index fed54532..3a8a168a 100644
--- a/core/src/test/java/tech/tablesaw/api/StringColumnTest.java
+++ b/core/src/test/java/tech/tablesaw/api/StringColumnTest.java
@@ -751,6 +751,28 @@ class StringColumnTest {
     assertEquals(3, col.asStringColumn().unique().size());
   }
 
+  @Test
+  public void isIn() {
+    String[] data = {"1", "1", "2", "2", "3", "4"};
+    StringColumn col = StringColumn.create("col", data);
+    Table t = Table.create("t", col);
+    String[] data1 = {"1", "2"};
+    StringColumn col1 = StringColumn.create("col1", data1);
+    Table t2 = t.where(t.stringColumn("col").isIn(col1));
+    assertEquals(4, t2.rowCount());
+  }
+
+  @Test
+  public void isNotIn() {
+    String[] data = {"1", "1", "2", "2", "3", "4"};
+    StringColumn col = StringColumn.create("col", data);
+    Table t = Table.create("t", col);
+    String[] data1 = {"1", "2"};
+    StringColumn col1 = StringColumn.create("col1", data1);
+    Table t2 = t.where(t.stringColumn("col").isNotIn(col1));
+    assertEquals(2, t2.rowCount());
+  }
+
   @Test
   public void countUniqueWithMissing() {
     StringColumn col1 = StringColumn.create("col1");
diff --git a/core/src/test/java/tech/tablesaw/api/TableTest.java b/core/src/test/java/tech/tablesaw/api/TableTest.java
index 6b1a5843..8041622d 100644
--- a/core/src/test/java/tech/tablesaw/api/TableTest.java
+++ b/core/src/test/java/tech/tablesaw/api/TableTest.java
@@ -37,6 +37,7 @@ import tech.tablesaw.columns.Column;
 import tech.tablesaw.columns.dates.PackedLocalDate;
 import tech.tablesaw.columns.numbers.IntColumnType;
 import tech.tablesaw.io.csv.CsvReadOptions;
+import tech.tablesaw.table.TableSlice;
 
 public class TableTest {
 
@@ -564,6 +565,16 @@ public class TableTest {
         });
   }
 
+  @Test
+  void testAppendWithSlice() throws Exception {
+    Table t = Table.read().csv("../data/bush.csv");
+    Table t2 = t.emptyCopy();
+    TableSlice slice = t.splitOn("who").get(0);
+    t2.append(slice);
+    assertEquals(64, t2.rowCount());
+  }
+
+  @Test
   void testAppendTableWithNonExistingColumns() {
     assertThrows(
         IllegalStateException.class,
@@ -573,6 +584,7 @@ public class TableTest {
         });
   }
 
+  @Test
   void testAppendTableWithAnotherColumnName() {
     assertThrows(
         IllegalStateException.class,
@@ -583,6 +595,7 @@ public class TableTest {
         });
   }
 
+  @Test
   void testAppendTableWithDifferentShape() {
     assertThrows(
         IllegalStateException.class,
diff --git a/core/src/test/java/tech/tablesaw/columns/numbers/NumberFiltersTest.java b/core/src/test/java/tech/tablesaw/columns/numbers/NumberFiltersTest.java
index 792fa713..776c9d61 100644
--- a/core/src/test/java/tech/tablesaw/columns/numbers/NumberFiltersTest.java
+++ b/core/src/test/java/tech/tablesaw/columns/numbers/NumberFiltersTest.java
@@ -1,10 +1,13 @@
 package tech.tablesaw.columns.numbers;
 
 import static java.lang.Double.NaN;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import org.junit.jupiter.api.Test;
 import tech.tablesaw.api.DoubleColumn;
+import tech.tablesaw.api.FloatColumn;
+import tech.tablesaw.api.IntColumn;
 import tech.tablesaw.api.Table;
 import tech.tablesaw.io.csv.CsvReadOptions;
 import tech.tablesaw.selection.Selection;
@@ -50,6 +53,27 @@ public class NumberFiltersTest {
     assertEquals(1, selection.size());
   }
 
+  @Test
+  public void asIntArray() {
+    int[] values = {4, 1, 1, 2, 2, 5, 7};
+    IntColumn int1 = IntColumn.create("ints", values);
+    assertArrayEquals(values, int1.asIntArray());
+  }
+
+  @Test
+  public void asFloatArray() {
+    float[] values = {4, 1, 1, 2, 2, 5, 7};
+    FloatColumn c1 = FloatColumn.create("f", values);
+    assertArrayEquals(values, c1.asFloatArray());
+  }
+
+  @Test
+  public void asDoubleArray() {
+    double[] values = {4, 1, 1, 2, 2, 5, 7};
+    DoubleColumn c1 = DoubleColumn.create("f", values);
+    assertArrayEquals(values, c1.asDoubleArray());
+  }
+
   @Test
   public void testIsNegative() {
     double[] values = {4, 0, -0.00001};