Skip to content

string casing functions #2550

@universalmind303

Description

@universalmind303

Is your feature request related to a problem? Please describe.
Sometimes I have some columns or other text that is in one casing, such as camelCase and I want to apply a transformation to convert that to another casing, such as snake_case

Describe the solution you'd like

df = daft.from_pydict({'text': ['helloWorld', 'hello-world', 'HelloWorld']})
df.with_columns(
camel_case = col('text').str.to_camel_case(),
upper_camel_case = col('text').str.to_upper_camel_case(),
snake_case = col('text').str.to_snake_case(),
upper_snake_case = col('text').str.to_upper_snake_case(),
kebab_case = col('text').str.to_kebab_case(),
upper_kebab_case = col('text').str.to_upper_kebab_case(),
)


df = daft.from_pydict({'text': ['helloWorld', 'hello-world', 'HelloWorld']})
df.with_columns(
camel_case = col('text').str.to_camel_case(),
upper_camel_case = col('text').str.to_upper_camel_case(),
snake_case = col('text').str.to_snake_case(),
upper_snake_case = col('text').str.to_upper_snake_case(),
kebab_case = col('text').str.to_kebab_case(),
upper_kebab_case = col('text').str.to_upper_kebab_case(),
title_case = col('text').str.to_title_case(),
)

# expected 
expected = {
    'camel_case': ['helloWorld', 'helloWorld', 'helloWorld'],
    'upper_camel_case': ['HelloWorld', 'HelloWorld', 'HelloWorld'],
    'snake_case': ['hello_world', 'hello_world', 'hello_world'],
    'upper_snake_case': ['HELLO_WORLD', 'HELLO_WORLD', 'HELLO_WORLD'],
    'kebab_case': ['hello-world', 'hello-world', 'hello-world'],
    'upper_kebab_case': ['HELLO-WORLD', 'HELLO-WORLD', 'HELLO-WORLD'],
    'title_case': ['Hello World', 'Hello World', 'Hello World']
}

Describe alternatives you've considered
udfs

Additional context
heck seems like a highly popular library that can do this

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions