Skip to content

Deprecation of iterable in the API with the addition of new methods #320

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

Merged
merged 8 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jetbrains.kotlinx.dataframe.api.rows
import org.jetbrains.kotlinx.dataframe.api.select
import org.jetbrains.kotlinx.dataframe.api.toDataFrame
import org.jetbrains.kotlinx.dataframe.columns.UnresolvedColumnsPolicy
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.impl.DataFrameImpl
import org.jetbrains.kotlinx.dataframe.impl.DataFrameSize
import org.jetbrains.kotlinx.dataframe.impl.getColumnsImpl
Expand Down Expand Up @@ -57,8 +58,12 @@ public interface DataFrame<out T> : Aggregatable<T>, ColumnsContainer<T> {
override operator fun <C> get(columns: ColumnsSelector<T, C>): List<DataColumn<C>> =
getColumnsImpl(UnresolvedColumnsPolicy.Fail, columns)

public operator fun get(first: AnyColumnReference, vararg other: AnyColumnReference): DataFrame<T> = select(listOf(first) + other)
public operator fun get(first: String, vararg other: String): DataFrame<T> = select(listOf(first) + other)
public operator fun get(first: AnyColumnReference, vararg other: AnyColumnReference): DataFrame<T> =
select { (listOf(first) + other).toColumnSet() }

public operator fun get(first: String, vararg other: String): DataFrame<T> =
select { (listOf(first) + other).toColumnSet() }

public operator fun get(columnRange: ClosedRange<String>): DataFrame<T> =
select { columnRange.start..columnRange.endInclusive }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum

// region select

public fun <C> ColumnSet<DataRow<C>>.select(vararg columns: String): ColumnSet<*> = select { columns.toColumns() }
public fun <C> ColumnSet<DataRow<C>>.select(vararg columns: String): ColumnSet<*> = select { columns.toColumnSet() }

public fun <C, R> ColumnSet<DataRow<C>>.select(vararg columns: KProperty<R>): ColumnSet<R> =
select { columns.toColumns() }
select { columns.toColumnSet() }

public fun <C, R> ColumnSet<DataRow<C>>.select(selector: ColumnsSelector<C, R>): ColumnSet<R> = createColumnSet {
this@select.resolve(it).flatMap { group ->
Expand Down Expand Up @@ -270,16 +270,16 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
public fun ColumnSet<*>.startsWith(prefix: CharSequence): ColumnSet<Any?> = cols { it.name.startsWith(prefix) }
public fun ColumnSet<*>.endsWith(suffix: CharSequence): ColumnSet<Any?> = cols { it.name.endsWith(suffix) }

public fun <C> ColumnSet<C>.except(vararg other: ColumnSet<*>): ColumnSet<*> = except(other.toColumns())
public fun <C> ColumnSet<C>.except(vararg other: String): ColumnSet<*> = except(other.toColumns())
public fun <C> ColumnSet<C>.except(vararg other: ColumnSet<*>): ColumnSet<*> = except(other.toColumnSet())
public fun <C> ColumnSet<C>.except(vararg other: String): ColumnSet<*> = except(other.toColumnSet())

public fun <C> ColumnSet<C?>.withoutNulls(): ColumnSet<C> = transform { it.filter { !it.hasNulls } } as ColumnSet<C>

public infix fun <C> ColumnSet<C>.except(other: ColumnSet<*>): ColumnSet<*> =
createColumnSet { resolve(it).allColumnsExcept(other.resolve(it)) }

public infix fun <C> ColumnSet<C>.except(selector: ColumnsSelector<T, *>): ColumnSet<C> =
except(selector.toColumns()) as ColumnSet<C>
except(selector.toColumnSet()) as ColumnSet<C>

public operator fun <C> ColumnsSelector<T, C>.invoke(): ColumnSet<C> =
this(this@ColumnsSelectionDsl, this@ColumnsSelectionDsl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
import org.jetbrains.kotlinx.dataframe.columns.UnresolvedColumnsPolicy
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.impl.columnName
import org.jetbrains.kotlinx.dataframe.impl.columns.asAnyFrameColumn
import org.jetbrains.kotlinx.dataframe.impl.columns.toColumns
import org.jetbrains.kotlinx.dataframe.impl.getColumnPaths
import org.jetbrains.kotlinx.dataframe.impl.getColumnsWithPaths
import org.jetbrains.kotlinx.dataframe.ncol
Expand All @@ -32,7 +32,7 @@ public fun <T, C> DataFrame<T>.getColumnPaths(selector: ColumnsSelector<T, C>):

public fun <T, C> DataFrame<T>.getColumnWithPath(selector: ColumnSelector<T, C>): ColumnWithPath<C> = getColumnsWithPaths(selector).single()
public fun <T, C> DataFrame<T>.getColumns(selector: ColumnsSelector<T, C>): List<DataColumn<C>> = get(selector)
public fun <T> DataFrame<T>.getColumns(vararg columns: String): List<AnyCol> = getColumns { columns.toColumns() }
public fun <T> DataFrame<T>.getColumns(vararg columns: String): List<AnyCol> = getColumns { columns.toColumnSet() }

public fun <T> DataFrame<T>.getColumnIndex(col: AnyCol): Int = getColumnIndex(col.name())
public fun <T> DataFrame<T>.getRows(range: IntRange): DataFrame<T> = if (range == indices()) this else columns().map { col -> col[range] }.toDataFrame().cast()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import org.jetbrains.kotlinx.dataframe.*
import org.jetbrains.kotlinx.dataframe.api.Update.UpdateOperationArg
import org.jetbrains.kotlinx.dataframe.columns.ColumnKind
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.documentation.*
import org.jetbrains.kotlinx.dataframe.impl.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.impl.columns.toColumns
import org.jetbrains.kotlinx.dataframe.util.ITERABLE_COLUMNS_DEPRECATION_MESSAGE
import kotlin.reflect.KProperty

// region fillNulls
Expand Down Expand Up @@ -120,7 +120,7 @@ public fun <T, C> DataFrame<T>.fillNulls(columns: ColumnsSelector<T, C?>): Updat
* @param columns The [Column names][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.ColumnNames.WithExample] belonging to this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to update.
*/
public fun <T> DataFrame<T>.fillNulls(vararg columns: String): Update<T, Any?> =
fillNulls { columns.toColumns() }
fillNulls { columns.toColumnSet() }

/**
* ## The Fill Nulls Operation
Expand Down Expand Up @@ -148,7 +148,7 @@ public fun <T> DataFrame<T>.fillNulls(vararg columns: String): Update<T, Any?> =
* @param columns The [KProperties][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.KProperties.WithExample] corresponding to columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to update.
*/
public fun <T, C> DataFrame<T>.fillNulls(vararg columns: KProperty<C>): Update<T, C?> =
fillNulls { columns.toColumns() }
fillNulls { columns.toColumnSet() }

/**
* ## The Fill Nulls Operation
Expand Down Expand Up @@ -178,11 +178,16 @@ public fun <T, C> DataFrame<T>.fillNulls(vararg columns: KProperty<C>): Update<T
* @param columns The [Column references][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.ColumnAccessors.WithExample] of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to update.
*/
public fun <T, C> DataFrame<T>.fillNulls(vararg columns: ColumnReference<C>): Update<T, C?> =
fillNulls { columns.toColumns() }
fillNulls { columns.toColumnSet() }

/**
* TODO this will be deprecated [PR #286](https://github.com/Kotlin/dataframe/pull/320)
*/
@Deprecated(
message = ITERABLE_COLUMNS_DEPRECATION_MESSAGE,
replaceWith = ReplaceWith(
"fillNulls { columns.toColumnSet() }",
"org.jetbrains.kotlinx.dataframe.columns.toColumnSet",
),
level = DeprecationLevel.ERROR,
)
public fun <T, C> DataFrame<T>.fillNulls(columns: Iterable<ColumnReference<C>>): Update<T, C?> =
fillNulls { columns.toColumnSet() }

Expand Down Expand Up @@ -313,7 +318,7 @@ public fun <T, C> DataFrame<T>.fillNaNs(columns: ColumnsSelector<T, C>): Update<
* @param columns The [Column names][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.ColumnNames.WithExample] belonging to this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to update.
*/
public fun <T> DataFrame<T>.fillNaNs(vararg columns: String): Update<T, Any?> =
fillNaNs { columns.toColumns() }
fillNaNs { columns.toColumnSet() }

/**
* ## The Fill NaNs Operation
Expand All @@ -339,7 +344,7 @@ public fun <T> DataFrame<T>.fillNaNs(vararg columns: String): Update<T, Any?> =
* @param columns The [KProperties][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.KProperties.WithExample] corresponding to columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to update.
*/
public fun <T, C> DataFrame<T>.fillNaNs(vararg columns: KProperty<C>): Update<T, C> =
fillNaNs { columns.toColumns() }
fillNaNs { columns.toColumnSet() }

/**
* ## The Fill NaNs Operation
Expand Down Expand Up @@ -367,11 +372,16 @@ public fun <T, C> DataFrame<T>.fillNaNs(vararg columns: KProperty<C>): Update<T,
* @param columns The [Column references][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.ColumnAccessors.WithExample] of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to update.
*/
public fun <T, C> DataFrame<T>.fillNaNs(vararg columns: ColumnReference<C>): Update<T, C> =
fillNaNs { columns.toColumns() }
fillNaNs { columns.toColumnSet() }

/**
* TODO this will be deprecated [PR #286](https://github.com/Kotlin/dataframe/pull/320)
*/
@Deprecated(
message = ITERABLE_COLUMNS_DEPRECATION_MESSAGE,
replaceWith = ReplaceWith(
"fillNaNs { columns.toColumnSet() }",
"org.jetbrains.kotlinx.dataframe.columns.toColumnSet",
),
level = DeprecationLevel.ERROR,
)
public fun <T, C> DataFrame<T>.fillNaNs(columns: Iterable<ColumnReference<C>>): Update<T, C> =
fillNaNs { columns.toColumnSet() }

Expand Down Expand Up @@ -482,7 +492,7 @@ public fun <T, C> DataFrame<T>.fillNA(columns: ColumnsSelector<T, C?>): Update<T
* @param columns The [Column names][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.ColumnNames.WithExample] belonging to this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to update.
*/
public fun <T> DataFrame<T>.fillNA(vararg columns: String): Update<T, Any?> =
fillNA { columns.toColumns() }
fillNA { columns.toColumnSet() }

/**
* ## The Fill NA Operation
Expand All @@ -508,7 +518,7 @@ public fun <T> DataFrame<T>.fillNA(vararg columns: String): Update<T, Any?> =
* @param columns The [KProperties][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.KProperties.WithExample] corresponding to columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to update.
*/
public fun <T, C> DataFrame<T>.fillNA(vararg columns: KProperty<C>): Update<T, C?> =
fillNA { columns.toColumns() }
fillNA { columns.toColumnSet() }

/**
* ## The Fill NA Operation
Expand Down Expand Up @@ -536,11 +546,16 @@ public fun <T, C> DataFrame<T>.fillNA(vararg columns: KProperty<C>): Update<T, C
* @param columns The [Column references][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.ColumnAccessors.WithExample] of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to update.
*/
public fun <T, C> DataFrame<T>.fillNA(vararg columns: ColumnReference<C>): Update<T, C?> =
fillNA { columns.toColumns() }
fillNA { columns.toColumnSet() }

/**
* TODO this will be deprecated [PR #286](https://github.com/Kotlin/dataframe/pull/320)
*/
@Deprecated(
message = ITERABLE_COLUMNS_DEPRECATION_MESSAGE,
replaceWith = ReplaceWith(
"fillNA { columns.toColumnSet() }",
"org.jetbrains.kotlinx.dataframe.columns.toColumnSet",
),
level = DeprecationLevel.ERROR,
)
public fun <T, C> DataFrame<T>.fillNA(columns: Iterable<ColumnReference<C>>): Update<T, C?> =
fillNA { columns.toColumnSet() }

Expand Down Expand Up @@ -682,7 +697,7 @@ public fun <T> DataFrame<T>.dropNulls(whereAllNull: Boolean = false): DataFrame<
* @param columns The [KProperties][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.KProperties.WithExample] used to select the columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to drop rows in.
*/
public fun <T> DataFrame<T>.dropNulls(vararg columns: KProperty<*>, whereAllNull: Boolean = false): DataFrame<T> =
dropNulls(whereAllNull) { columns.toColumns() }
dropNulls(whereAllNull) { columns.toColumnSet() }

/**
* ## The Drop Nulls Operation
Expand All @@ -709,7 +724,7 @@ public fun <T> DataFrame<T>.dropNulls(vararg columns: KProperty<*>, whereAllNull
* @param columns The [Column names][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.ColumnNames.WithExample] used to select the columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to drop rows in.
*/
public fun <T> DataFrame<T>.dropNulls(vararg columns: String, whereAllNull: Boolean = false): DataFrame<T> =
dropNulls(whereAllNull) { columns.toColumns() }
dropNulls(whereAllNull) { columns.toColumnSet() }

/**
* ## The Drop Nulls Operation
Expand Down Expand Up @@ -741,11 +756,16 @@ public fun <T> DataFrame<T>.dropNulls(vararg columns: String, whereAllNull: Bool
* ([Column Accessors API][org.jetbrains.kotlinx.dataframe.documentation.AccessApi.ColumnAccessorsApi]). used to select the columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to drop rows in.
*/
public fun <T> DataFrame<T>.dropNulls(vararg columns: AnyColumnReference, whereAllNull: Boolean = false): DataFrame<T> =
dropNulls(whereAllNull) { columns.toColumns() }
dropNulls(whereAllNull) { columns.toColumnSet() }

/**
* TODO this will be deprecated [PR #286](https://github.com/Kotlin/dataframe/pull/320)
*/
@Deprecated(
message = ITERABLE_COLUMNS_DEPRECATION_MESSAGE,
replaceWith = ReplaceWith(
"dropNulls(whereAllNull) { columns.toColumnSet() }",
"org.jetbrains.kotlinx.dataframe.columns.toColumnSet",
),
level = DeprecationLevel.ERROR,
)
public fun <T> DataFrame<T>.dropNulls(
columns: Iterable<AnyColumnReference>,
whereAllNull: Boolean = false,
Expand Down Expand Up @@ -866,7 +886,7 @@ public fun <T> DataFrame<T>.dropNA(whereAllNA: Boolean = false, columns: Columns
* @param columns The [KProperties][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.KProperties.WithExample] used to select the columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to drop rows in.
*/
public fun <T> DataFrame<T>.dropNA(vararg columns: KProperty<*>, whereAllNA: Boolean = false): DataFrame<T> =
dropNA(whereAllNA) { columns.toColumns() }
dropNA(whereAllNA) { columns.toColumnSet() }

/**
* ## The Drop `NA` Operation
Expand All @@ -893,7 +913,7 @@ public fun <T> DataFrame<T>.dropNA(vararg columns: KProperty<*>, whereAllNA: Boo
* @param columns The [Column names][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.ColumnNames.WithExample] used to select the columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to drop rows in.
*/
public fun <T> DataFrame<T>.dropNA(vararg columns: String, whereAllNA: Boolean = false): DataFrame<T> =
dropNA(whereAllNA) { columns.toColumns() }
dropNA(whereAllNA) { columns.toColumnSet() }

/**
* ## The Drop `NA` Operation
Expand Down Expand Up @@ -925,11 +945,16 @@ public fun <T> DataFrame<T>.dropNA(vararg columns: String, whereAllNA: Boolean =
* ([Column Accessors API][org.jetbrains.kotlinx.dataframe.documentation.AccessApi.ColumnAccessorsApi]). used to select the columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to drop rows in.
*/
public fun <T> DataFrame<T>.dropNA(vararg columns: AnyColumnReference, whereAllNA: Boolean = false): DataFrame<T> =
dropNA(whereAllNA) { columns.toColumns() }
dropNA(whereAllNA) { columns.toColumnSet() }

/**
* TODO this will be deprecated [PR #286](https://github.com/Kotlin/dataframe/pull/320)
*/
@Deprecated(
message = ITERABLE_COLUMNS_DEPRECATION_MESSAGE,
replaceWith = ReplaceWith(
"dropNA(whereAllNA) { columns.toColumnSet() }",
"org.jetbrains.kotlinx.dataframe.columns.toColumnSet",
),
level = DeprecationLevel.ERROR,
)
public fun <T> DataFrame<T>.dropNA(columns: Iterable<AnyColumnReference>, whereAllNA: Boolean = false): DataFrame<T> =
dropNA(whereAllNA) { columns.toColumnSet() }

Expand Down Expand Up @@ -1069,7 +1094,7 @@ public fun <T> DataFrame<T>.dropNaNs(whereAllNaN: Boolean = false, columns: Colu
* @param columns The [KProperties][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.KProperties.WithExample] used to select the columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to drop rows in.
*/
public fun <T> DataFrame<T>.dropNaNs(vararg columns: KProperty<*>, whereAllNaN: Boolean = false): DataFrame<T> =
dropNaNs(whereAllNaN) { columns.toColumns() }
dropNaNs(whereAllNaN) { columns.toColumnSet() }

/**
* ## The Drop `NaN` Operation
Expand All @@ -1096,7 +1121,7 @@ public fun <T> DataFrame<T>.dropNaNs(vararg columns: KProperty<*>, whereAllNaN:
* @param columns The [Column names][org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.ColumnNames.WithExample] used to select the columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to drop rows in.
*/
public fun <T> DataFrame<T>.dropNaNs(vararg columns: String, whereAllNaN: Boolean = false): DataFrame<T> =
dropNaNs(whereAllNaN) { columns.toColumns() }
dropNaNs(whereAllNaN) { columns.toColumnSet() }

/**
* ## The Drop `NaN` Operation
Expand Down Expand Up @@ -1128,11 +1153,16 @@ public fun <T> DataFrame<T>.dropNaNs(vararg columns: String, whereAllNaN: Boolea
* ([Column Accessors API][org.jetbrains.kotlinx.dataframe.documentation.AccessApi.ColumnAccessorsApi]). used to select the columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to drop rows in.
*/
public fun <T> DataFrame<T>.dropNaNs(vararg columns: AnyColumnReference, whereAllNaN: Boolean = false): DataFrame<T> =
dropNaNs(whereAllNaN) { columns.toColumns() }
dropNaNs(whereAllNaN) { columns.toColumnSet() }

/**
* TODO this will be deprecated [PR #286](https://github.com/Kotlin/dataframe/pull/320)
*/
@Deprecated(
message = ITERABLE_COLUMNS_DEPRECATION_MESSAGE,
replaceWith = ReplaceWith(
"dropNaNs(whereAllNaN) { columns.toColumnSet() }",
"org.jetbrains.kotlinx.dataframe.columns.toColumnSet",
),
level = DeprecationLevel.ERROR,
)
public fun <T> DataFrame<T>.dropNaNs(
columns: Iterable<AnyColumnReference>,
whereAllNaN: Boolean = false,
Expand Down
Loading