Skip to content
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

NullPointerException using except to exclude double nested column #761

Open
Jolanrensen opened this issue Jul 1, 2024 · 3 comments
Open
Labels
bug Something isn't working
Milestone

Comments

@Jolanrensen
Copy link
Collaborator

To reproduce:

val df = dataFrameOf("a.b", "a.c.d", "d.e", "d.f")(1, 3.0, 2, "b")
    .move { all() }.into { it.name.split(".").toPath() }
a d
{"b": 1, "c": {"d": 3}} {"e": 2, "f": "b"}

This works:

df.select { cols(a) except a.b }

This breaks:

df.select { cols(a) except a.c.d }
java.lang.NullPointerException
	at org.jetbrains.kotlinx.dataframe.impl.columns.UtilsKt$allColumnsExceptKeepingStructure$2.invoke(Utils.kt:454)
	at org.jetbrains.kotlinx.dataframe.impl.columns.UtilsKt$allColumnsExceptKeepingStructure$2.invoke(Utils.kt:454)
	at org.jetbrains.kotlinx.dataframe.api.ReplaceKt.with(replace.kt:53)
	at org.jetbrains.kotlinx.dataframe.impl.columns.UtilsKt.allColumnsExceptKeepingStructure(Utils.kt:454)
	at org.jetbrains.kotlinx.dataframe.impl.columns.UtilsKt.allColumnsExceptKeepingStructure$default(Utils.kt:412)
	at org.jetbrains.kotlinx.dataframe.api.AllExceptKt$exceptInternal$1.invoke(allExcept.kt:1193)
	at org.jetbrains.kotlinx.dataframe.api.AllExceptKt$exceptInternal$1.invoke(allExcept.kt:1190)
	at org.jetbrains.kotlinx.dataframe.impl.columns.ConstructorsKt$createColumnSet$1.resolve(constructors.kt:154)
	at org.jetbrains.kotlinx.dataframe.impl.columns.UtilsKt.resolve(Utils.kt:480)
	at org.jetbrains.kotlinx.dataframe.impl.columns.ConstructorsKt$toColumnSet$1.invoke(constructors.kt:178)
	at org.jetbrains.kotlinx.dataframe.impl.columns.ConstructorsKt$toColumnSet$1.invoke(constructors.kt:175)
	at org.jetbrains.kotlinx.dataframe.impl.columns.ConstructorsKt$createColumnSet$1.resolve(constructors.kt:154)
	at org.jetbrains.kotlinx.dataframe.impl.columns.UtilsKt.resolve(Utils.kt:480)
	at org.jetbrains.kotlinx.dataframe.impl.UtilsKt.getColumnsWithPaths(Utils.kt:201)
	at org.jetbrains.kotlinx.dataframe.impl.UtilsKt.getColumnsImpl(Utils.kt:196)
	at org.jetbrains.kotlinx.dataframe.DataFrame$DefaultImpls.get(DataFrame.kt:78)
	at org.jetbrains.kotlinx.dataframe.impl.DataFrameImpl.get(DataFrameImpl.kt:32)
	at org.jetbrains.kotlinx.dataframe.api.SelectKt.select(select.kt:64)
	at Line_70_jupyter.<init>(Line_70.jupyter.kts:1)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
@Jolanrensen Jolanrensen added the bug Something isn't working label Jul 1, 2024
@koperagen
Copy link
Collaborator

Let's consider making except work only for selected columns and not their children

@Jolanrensen
Copy link
Collaborator Author

Yes, that might be a good idea. Many operations can be reproduced with remove + except. And this case is just an edge-case.

exceptNew does look promising, but we could reconsider it, as it's experimental anyway.

Eventually, we might want another way to be able to select a column and keep its parents structure (so select its parents, but delete its siblings). But we can sorta reproduce that already by doing something like:

df.getColumnsWithPaths { colsAtAnyDepth().colsOf<Int>() }
    .map { it.path to it }
    .toDataFrameFromPairs<Any?>()

@zaleslaw zaleslaw added the good first issue Good issues to pick-up for newcomers label Jul 19, 2024
@zaleslaw zaleslaw added this to the 0.14.0 milestone Jul 19, 2024
@Jolanrensen
Copy link
Collaborator Author

Not sure if this is a good first issue. It may be a difficult one, but if someone's up for it, I'd be happy to help

@zaleslaw zaleslaw removed the good first issue Good issues to pick-up for newcomers label Sep 16, 2024
@zaleslaw zaleslaw modified the milestones: 0.14.0, Backlog Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants