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

DataFrame.parse should allow users to pass their custom parsers #741

Open
koperagen opened this issue Jun 17, 2024 · 0 comments
Open

DataFrame.parse should allow users to pass their custom parsers #741

koperagen opened this issue Jun 17, 2024 · 0 comments
Labels
enhancement New feature or request files reading/writing from/to files
Milestone

Comments

@koperagen
Copy link
Collaborator

koperagen commented Jun 17, 2024

Suggested API:

class MyWrapper(val value: Int)

//either global configuration
DataFrame.parsers.add(
    stringParser { if(it.endsWith("%")) it.dropLast(1).toIntOrNull()?.let { MyWrapper(it) } else null }
)

// or provide instance here 
val df = dataFrameOf("a","b")("55%", "12%").parse(/*ParserOptions(...)*/)
df["a"].type() shouldBe typeOf<MyWrapper>()
df["b"].type() shouldBe typeOf<MyWrapper>()

Should save some effort manually selecting columns for conversion or writing a complex column selector that should somehow tell column can be parsed.

dataFrameOf("a","b")("55%", "12%").convert { 
    colsAtAnyDepth()
        .colsOf<String>()
        .filter {
            it.values().all { it.toPercentageOrNull() != null } 
        } 
}.with { it.toPercentageOrNull()!! }

Instead, all you'd need to define is (String) -> YourType? function

@koperagen koperagen added the enhancement New feature or request label Jun 17, 2024
@zaleslaw zaleslaw added the files reading/writing from/to files label Jul 19, 2024
@zaleslaw zaleslaw added this to the Backlog milestone Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request files reading/writing from/to files
Projects
None yet
Development

No branches or pull requests

2 participants