Skip to content

MINOR: add unit tests for chr function #16856

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

Merged
merged 5 commits into from
Jul 24, 2025
Merged

MINOR: add unit tests for chr function #16856

merged 5 commits into from
Jul 24, 2025

Conversation

waynexia
Copy link
Member

@waynexia waynexia commented Jul 22, 2025

Which issue does this PR close?

  • Closes #.

Rationale for this change

I wonder if chr() works for larger or negative input when reading #14700, as I read from encode_utf8 would panic if the provided buffer is not large enough. So I added some unit test cases to verify. It turns out chr() can handle input like i64::MAX (gated by core::char::from_u32), but it does miss the negative case.

What changes are included in this PR?

Add unit tests to chr() function. And check if the input is negative.

My local bench result shows the extra check won't slow this function by a lot

chr                     time:   [5.1686 µs 5.1726 µs 5.1774 µs]
                        change: [+0.3217% +0.4109% +0.5066%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe

Are these changes tested?

yes

Are there any user-facing changes?

waynexia added 2 commits July 23, 2025 02:17
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
@github-actions github-actions bot added the functions Changes to functions implementation label Jul 22, 2025
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
waynexia added 2 commits July 24, 2025 02:35
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
@findepi findepi merged commit 07516aa into apache:main Jul 24, 2025
27 checks passed
@waynexia waynexia deleted the chr-ut branch July 24, 2025 18:15
@waynexia
Copy link
Member Author

Thank you for reviewing @findepi @alamb ❤️

adriangb pushed a commit to pydantic/datafusion that referenced this pull request Jul 28, 2025
* MINOR: add unit tests for chr function

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* handle negative input

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* fix clippy

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* add more test cases

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* add a surrogate codepoint case

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

---------

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
functions Changes to functions implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants