Skip to content

Commit

Permalink
add SQL docs/example
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie committed Jan 15, 2025
1 parent fa2cc22 commit a8ac92d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/polars-sql/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ pub(crate) enum PolarsSQLFunctions {
LTrim,
/// SQL 'normalize' function
/// Convert string to Unicode normalization form
/// (one of "NFC", "NFKC", "NFD", or "NFKD").
/// (one of NFC, NFKC, NFD, or NFKD - unquoted).
/// ```sql
/// SELECT NORMALIZE(column_1, 'NFC') FROM df;
/// SELECT NORMALIZE(column_1, NFC) FROM df;
/// ```
Normalize,
/// SQL 'octet_length' function
Expand Down
35 changes: 35 additions & 0 deletions py-polars/docs/source/reference/sql/functions/string.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ String
- Returns a lowercased column.
* - :ref:`LTRIM <ltrim>`
- Strips whitespaces from the left.
* - :ref:`NORMALIZE <normalize>`
- Convert string to the specified Unicode normalization form (one of NFC, NFD, NFKC, NFKD).
* - :ref:`OCTET_LENGTH <octet_length>`
- Returns the length of a given string in bytes.
* - :ref:`REGEXP_LIKE <regexp_like>`
Expand Down Expand Up @@ -366,6 +368,39 @@ Strips whitespaces from the left.
# │ DD ┆ DD │
# └───────┴─────────┘
.. _normalize:

NORMALIZE
---------
Convert string to the specified Unicode normalization form (one of NFC, NFD, NFKC, NFKD).
If the normalization form is not provided, NFC is used by default.

**Example:**

.. code-block:: python
df = pl.DataFrame({
"txt": [
"Test",
"Ⓣⓔⓢⓣ",
"𝕿𝖊𝖘𝖙",
"𝕋𝕖𝕤𝕥",
"𝗧𝗲𝘀𝘁",
],
})
df.sql("""
SELECT NORMALIZE(txt, NFKC) FROM self
""").to_series()
# shape: (5,)
# Series: 'txt' [str]
# [
# "Test"
# "Test"
# "Test"
# "Test"
# "Test"
# ]
.. _octet_length:

OCTET_LENGTH
Expand Down

0 comments on commit a8ac92d

Please sign in to comment.