Skip to content

Commit

Permalink
Make Index more Series-like #271
Browse files Browse the repository at this point in the history
* Series.range() -> selectRange()
  • Loading branch information
andrus committed Mar 30, 2024
1 parent 1b5e89c commit c317f61
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 15 deletions.
11 changes: 10 additions & 1 deletion dflib/src/main/java/org/dflib/Series.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,18 @@ default LongSeries castAsLong() throws ClassCastException {
* @param fromInclusive a left boundary index of the returned range (included in the returned range)
* @param toExclusive a right boundary index (excluded in the returned range)
* @return a Series that contains a sub-range of data from this Series.
* @since 1.0.0-M21
*/
Series<T> selectRange(int fromInclusive, int toExclusive);

/**
* @since 1.0.0-M19
* @deprecated use {@link #selectRange(int, int)}
*/
Series<T> range(int fromInclusive, int toExclusive);
@Deprecated(since = "1.0.0-M21", forRemoval = true)
default Series<T> range(int fromInclusive, int toExclusive) {
return selectRange(fromInclusive, toExclusive);
}

/**
* Resolves the Series executing any lazy calculations. If called more than once, the first evaluation result is reused.
Expand Down
2 changes: 1 addition & 1 deletion dflib/src/main/java/org/dflib/concat/HConcat.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private UnaryOperator<Series<?>> seriesTrimmer(int seriesHeight, int desiredHeig
if (seriesHeight < desiredHeight) {
return s -> padSeries(s, desiredHeight - seriesHeight);
} else if (seriesHeight > desiredHeight) {
return s -> s.range(0, desiredHeight);
return s -> s.selectRange(0, desiredHeight);
} else {
return UnaryOperator.identity();
}
Expand Down
2 changes: 1 addition & 1 deletion dflib/src/main/java/org/dflib/series/ArrayRangeSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public Series<T> fillNullsForward() {
}

@Override
public Series<T> range(int fromInclusive, int toExclusive) {
public Series<T> selectRange(int fromInclusive, int toExclusive) {
return fromInclusive == 0 && toExclusive == size()
? this
: new ArrayRangeSeries<>(getNominalType(), data, fromInclusive, toExclusive - fromInclusive);
Expand Down
2 changes: 1 addition & 1 deletion dflib/src/main/java/org/dflib/series/ArraySeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public Series<T> fillNullsForward() {
}

@Override
public Series<T> range(int fromInclusive, int toExclusive) {
public Series<T> selectRange(int fromInclusive, int toExclusive) {
return fromInclusive == 0 && toExclusive == size()
? this
: new ArrayRangeSeries(getNominalType(), data, fromInclusive, toExclusive - fromInclusive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public DataFrame map(Index resultColumns, ValueToRowMapper<Boolean> mapper) {
}

@Override
public Series<Boolean> range(int fromInclusive, int toExclusive) {
public Series<Boolean> selectRange(int fromInclusive, int toExclusive) {
return rangeBool(fromInclusive, toExclusive);
}

Expand Down
2 changes: 1 addition & 1 deletion dflib/src/main/java/org/dflib/series/DoubleBaseSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public DataFrame map(Index resultColumns, ValueToRowMapper<Double> mapper) {
}

@Override
public Series<Double> range(int fromInclusive, int toExclusive) {
public Series<Double> selectRange(int fromInclusive, int toExclusive) {
return rangeDouble(fromInclusive, toExclusive);
}

Expand Down
4 changes: 2 additions & 2 deletions dflib/src/main/java/org/dflib/series/IndexedSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public void copyTo(Object[] to, int fromOffset, int toOffset, int len) {
}

@Override
public Series<T> range(int fromInclusive, int toExclusive) {
public Series<T> selectRange(int fromInclusive, int toExclusive) {
Raw<T> raw = this.raw;
return raw != null
? new IndexedSeries(raw.source, raw.includePositions.rangeInt(fromInclusive, toExclusive))
: materialized.range(fromInclusive, toExclusive);
: materialized.selectRange(fromInclusive, toExclusive);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion dflib/src/main/java/org/dflib/series/IntBaseSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public <S> Series<S> castAs(Class<S> type) {
}

@Override
public Series<Integer> range(int fromInclusive, int toExclusive) {
public Series<Integer> selectRange(int fromInclusive, int toExclusive) {
return rangeInt(fromInclusive, toExclusive);
}

Expand Down
2 changes: 1 addition & 1 deletion dflib/src/main/java/org/dflib/series/LongBaseSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public DataFrame map(Index resultColumns, ValueToRowMapper<Long> mapper) {
}

@Override
public Series<Long> range(int fromInclusive, int toExclusive) {
public Series<Long> selectRange(int fromInclusive, int toExclusive) {
return rangeLong(fromInclusive, toExclusive);
}

Expand Down
6 changes: 3 additions & 3 deletions dflib/src/main/java/org/dflib/series/ObjectSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public <S> Series<S> castAs(Class<S> type) {
}

@Override
public Series<T> range(int fromInclusive, int toExclusive) {
public Series<T> selectRange(int fromInclusive, int toExclusive) {

if (fromInclusive == toExclusive) {
return new EmptySeries<>();
Expand Down Expand Up @@ -152,7 +152,7 @@ public Series<T> head(int len) {
return this;
}

return len < 0 ? tail(size() + len) : range(0, len);
return len < 0 ? tail(size() + len) : selectRange(0, len);
}

@Override
Expand All @@ -163,7 +163,7 @@ public Series<T> tail(int len) {
return this;
}

return len < 0 ? head(size + len) : range(size - len, size);
return len < 0 ? head(size + len) : selectRange(size - len, size);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public Series<T> intersect(Series<? extends T> other) {
}

@Override
public Series<T> range(int fromInclusive, int toExclusive) {
public Series<T> selectRange(int fromInclusive, int toExclusive) {

if (fromInclusive == toExclusive) {
return new EmptySeries<>();
Expand Down
2 changes: 1 addition & 1 deletion dflib/src/main/java/org/dflib/slice/RangeRowSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected void doSelectByRow(RowMapper mapper, ColumnsRowProxy from, MultiArrayR

@Override
protected <T> Series<T> doSelect(Series<T> sourceColumn) {
return sourceColumn.range(fromInclusive, toExclusive);
return sourceColumn.selectRange(fromInclusive, toExclusive);
}

@Override
Expand Down

0 comments on commit c317f61

Please sign in to comment.