nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: jtablesaw/tablesaw
Pull request #1072 (2022-03-28 21:53:17)

fix for issue #1047 : setPrintFormatter causes NPE, plus test
Thanks for contributing.

- [x] Tick to sign-off your agreement to the [Developer Certificate of Origin (DCO) 1.1](https://developercertificate.org)

## Description

modified method to ensure that the ColumnType was set in the formatter

## Testing

Did you add a unit test? Yes



Patch:
diff --git a/core/src/main/java/tech/tablesaw/api/NumberColumn.java b/core/src/main/java/tech/tablesaw/api/NumberColumn.java
index 514966c5..b2ed9d8f 100644
--- a/core/src/main/java/tech/tablesaw/api/NumberColumn.java
+++ b/core/src/main/java/tech/tablesaw/api/NumberColumn.java
@@ -65,8 +65,8 @@ public abstract class NumberColumn<C extends NumberColumn<C, T>, T extends Numbe
 
   /** {@inheritDoc} */
   @Override
-  public void setPrintFormatter(final NumberFormat format, final String missingValueIndicator) {
-    this.printFormatter = new NumberColumnFormatter(format, missingValueIndicator);
+  public void setPrintFormatter(NumberFormat format, String missingValueIndicator) {
+    setPrintFormatter(new NumberColumnFormatter(format, missingValueIndicator));
   }
 
   /** {@inheritDoc} */


Test patch:
diff --git a/core/src/test/java/tech/tablesaw/api/NumberColumnTest.java b/core/src/test/java/tech/tablesaw/api/NumberColumnTest.java
index 4d201411..4a580838 100644
--- a/core/src/test/java/tech/tablesaw/api/NumberColumnTest.java
+++ b/core/src/test/java/tech/tablesaw/api/NumberColumnTest.java
@@ -30,9 +30,11 @@ import static tech.tablesaw.columns.numbers.NumberPredicates.isMissing;
 
 import com.google.common.base.Stopwatch;
 import java.math.BigDecimal;
+import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Locale;
 import java.util.concurrent.TimeUnit;
 import java.util.function.DoubleBinaryOperator;
 import java.util.function.DoubleFunction;
@@ -806,6 +808,14 @@ public class NumberColumnTest {
     }
   }
 
+  @Test
+  void testSetPrintFormatter() {
+    NumberColumn<DoubleColumn, Double> numberColumn = DoubleColumn.create("test");
+    numberColumn.append(48392.2932);
+    numberColumn.setPrintFormatter(NumberFormat.getCurrencyInstance(Locale.US), "");
+    assertEquals("$48,392.29", numberColumn.getString(0));
+  }
+
   @Test
   public void testFilter() {
     Column<Double> filtered =
Repository: jtablesaw/tablesaw
Pull request #1212 (2023-05-19 13:45:27)

Find last index of element in column
- [x] Tick to sign-off your agreement to the [Developer Certificate of Origin (DCO) 1.1](https://developercertificate.org)

## Description

Adds a new method `lastIndexOf` in `Column` to find the last index of a given occurence in a column. It comes in addition to `indexOf`. I find it usefull, especialy when working with time series.

## Testing

Comes with a unit test similar to what exists for `indexOf`.



Patch:
diff --git a/core/src/main/java/tech/tablesaw/columns/AbstractColumn.java b/core/src/main/java/tech/tablesaw/columns/AbstractColumn.java
index 31ab2d76..8fa22860 100644
--- a/core/src/main/java/tech/tablesaw/columns/AbstractColumn.java
+++ b/core/src/main/java/tech/tablesaw/columns/AbstractColumn.java
@@ -194,4 +194,11 @@ public abstract class AbstractColumn<C extends Column<T>, T> implements Column<T
   public int indexOf(final Object o) {
     return IntStream.range(0, size()).filter(i -> get(i).equals(o)).findFirst().orElse(-1);
   }
+
+  /** {@inheritDoc} */
+  @Override
+  public int lastIndexOf(Object o) {
+    return IntStream.iterate(size() - 1, i -> (i >= 0), i -> i - 1).filter(i -> get(i).equals(o))
+            .findFirst().orElse(-1);
+  }
 }
diff --git a/core/src/main/java/tech/tablesaw/columns/Column.java b/core/src/main/java/tech/tablesaw/columns/Column.java
index f88ebd2c..83ba1dc8 100644
--- a/core/src/main/java/tech/tablesaw/columns/Column.java
+++ b/core/src/main/java/tech/tablesaw/columns/Column.java
@@ -743,4 +743,10 @@ public interface Column<T> extends Iterable<T>, Comparator<T> {
    * not in the column.
    */
   int indexOf(Object o);
+
+  /**
+   * Returns the index of the last occurrence of {@code o} in the column or -1 if the element is not
+   * in the column.
+   */
+  int lastIndexOf(Object o);
 }


Test patch:
diff --git a/core/src/test/java/tech/tablesaw/columns/ColumnTest.java b/core/src/test/java/tech/tablesaw/columns/ColumnTest.java
index e07324ea..697ddbfe 100644
--- a/core/src/test/java/tech/tablesaw/columns/ColumnTest.java
+++ b/core/src/test/java/tech/tablesaw/columns/ColumnTest.java
@@ -338,4 +338,13 @@ public class ColumnTest {
     assertEquals(0, testDoubleCol.indexOf(0.0));
     assertEquals(1, testDoubleCol.indexOf(1.0));
   }
+
+  @Test
+  public void lastIndexOfTest() {
+    DoubleColumn testDoubleCol = DoubleColumn.create("t1", 0, 1, 1);
+    assertEquals(-1, testDoubleCol.lastIndexOf(2));
+    assertEquals(-1, testDoubleCol.lastIndexOf(0));
+    assertEquals(0, testDoubleCol.lastIndexOf(0.0));
+    assertEquals(2, testDoubleCol.lastIndexOf(1.0));
+  }
 }