Skip to content

Commit

Permalink
fix(backends): fix capitalize to lowercase subsequent characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattix23 authored and cpcloud committed Jun 16, 2023
1 parent 671bc31 commit 49978f9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ dist
.coverage
coverage.xml

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# OS generated files
.directory
.gdb_history
Expand Down
3 changes: 2 additions & 1 deletion ibis/backends/base/sql/alchemy/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,8 @@ class array_filter(FunctionElement):
# string
ops.Capitalize: unary(
lambda arg: sa.func.concat(
sa.func.upper(sa.func.substr(arg, 1, 1)), sa.func.substr(arg, 2)
sa.func.upper(sa.func.substr(arg, 1, 1)),
sa.func.lower(sa.func.substr(arg, 2)),
)
),
ops.LPad: fixed_arity(sa.func.lpad, 3),
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/bigquery/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def _array_slice(t, op):

def _capitalize(t, op):
arg = t.translate(op.arg)
return f"CONCAT(UPPER(SUBSTR({arg}, 1, 1)), SUBSTR({arg}, 2))"
return f"CONCAT(UPPER(SUBSTR({arg}, 1, 1)), LOWER(SUBSTR({arg}, 2)))"


def _nth_value(t, op):
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/clickhouse/compiler/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def _string_ilike(op, **kw):
@translate_val.register(ops.Capitalize)
def _string_capitalize(op, **kw):
arg = translate_val(op.arg, **kw)
return f"CONCAT(UPPER(SUBSTR({arg}, 1, 1)), SUBSTR({arg}, 2))"
return f"CONCAT(UPPER(SUBSTR({arg}, 1, 1)), LOWER(SUBSTR({arg}, 2)))"


@translate_val.register(ops.GroupConcat)
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/mssql/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _timestamp_truncate(t, op):
ops.Capitalize: unary(
lambda arg: sa.func.concat(
sa.func.upper(sa.func.substring(arg, 1, 1)),
sa.func.substring(arg, 2, sa.func.datalength(arg) - 1),
sa.func.lower(sa.func.substring(arg, 2, sa.func.datalength(arg) - 1)),
)
),
ops.LStrip: unary(sa.func.ltrim),
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ def test_parse_url(con, result_func, expected):


def test_capitalize(con):
s = ibis.literal("abc")
s = ibis.literal("aBc")
expected = "Abc"
expr = s.capitalize()
assert con.execute(expr) == expected
Expand Down

0 comments on commit 49978f9

Please sign in to comment.