-
Notifications
You must be signed in to change notification settings - Fork 76
Nothing cols fixes #1551
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
base: master
Are you sure you want to change the base?
Nothing cols fixes #1551
Changes from all commits
6608ebd
bf98cc4
e7805af
e72575b
a7f9498
0d009c6
f1a13c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ import org.jetbrains.kotlinx.dataframe.api.with | |
| import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup | ||
| import org.jetbrains.kotlinx.dataframe.columns.FrameColumn | ||
| import org.jetbrains.kotlinx.dataframe.columns.size | ||
| import org.jetbrains.kotlinx.dataframe.exceptions.DataFrameError | ||
| import org.jetbrains.kotlinx.dataframe.impl.columns.AddDataRowImpl | ||
| import org.jetbrains.kotlinx.dataframe.impl.createDataCollector | ||
| import org.jetbrains.kotlinx.dataframe.index | ||
|
|
@@ -94,28 +95,36 @@ private fun <C, R> ColumnGroup<C>.replaceRowsIf( | |
| .asColumnGroup() | ||
| .cast() | ||
|
|
||
| public class UpdateException(override val message: String, cause: Throwable? = null) : | ||
| IllegalStateException(message, cause), | ||
| DataFrameError | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to add this supertype only if you have example of code that triggers this in compiler plugin
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, that might be difficult, as it most often relies on runtime information. (besides maybe
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think about it as a way to opt-in reporting warnings for exceptions, that we know for sure make sense for user. In theory we could report any exception. DataFrameError will help us to validate them first
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. soo... DataFrameWarning? ;P
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be |
||
|
|
||
| internal fun <T, C> DataColumn<C>.updateImpl( | ||
| df: DataFrame<T>, | ||
| filter: RowValueFilter<T, C>?, | ||
| expression: (AddDataRow<T>, DataColumn<C>, C) -> C?, | ||
| ): DataColumn<C> { | ||
| val collector = createDataCollector<C>(size, type) | ||
| val src = this | ||
| if (filter == null) { | ||
| df.indices().forEach { rowIndex -> | ||
| val row = AddDataRowImpl(rowIndex, df, collector.values) | ||
| collector.add(expression(row, src, src[rowIndex])) | ||
| } | ||
| } else { | ||
| df.indices().forEach { rowIndex -> | ||
| val row = AddDataRowImpl(rowIndex, df, collector.values) | ||
| val currentValue = row[src] | ||
| val newValue = | ||
| if (filter.invoke(row, currentValue)) expression(row, src, currentValue) else currentValue | ||
| collector.add(newValue) | ||
| try { | ||
| if (filter == null) { | ||
| df.indices().forEach { rowIndex -> | ||
| val row = AddDataRowImpl(rowIndex, df, collector.values) | ||
| collector.add(expression(row, src, src[rowIndex])) | ||
| } | ||
| } else { | ||
| df.indices().forEach { rowIndex -> | ||
| val row = AddDataRowImpl(rowIndex, df, collector.values) | ||
| val currentValue = row[src] | ||
| val newValue = | ||
| if (filter.invoke(row, currentValue)) expression(row, src, currentValue) else currentValue | ||
| collector.add(newValue) | ||
| } | ||
| } | ||
| return collector.toColumn(src.name).cast() | ||
| } catch (e: Throwable) { | ||
| throw UpdateException("Could not update column '${src.name}': ${e.message}", e) | ||
| } | ||
| return collector.toColumn(src.name).cast() | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have two operations that use empty: concatImpl and getColumn. Please see if they can be affected by this change. Otherwise it's quite neat
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems
concatfails on dataframes without rows, but not because ofNothingcolumns, but because it uses::classreflection increateColumnGuessingType(), interestingThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it in the next commit :)