Skip to content

fix: allow bool dtype in zeros via typed_and_generic#11627

Closed
anandkaranubc wants to merge 1 commit intostdlib-js:developfrom
anandkaranubc:fix/array-zeros-bool-dtype
Closed

fix: allow bool dtype in zeros via typed_and_generic#11627
anandkaranubc wants to merge 1 commit intostdlib-js:developfrom
anandkaranubc:fix/array-zeros-bool-dtype

Conversation

@anandkaranubc
Copy link
Copy Markdown
Contributor

Resolves None

Description

What is the purpose of this pull request?

This pull request:

  • allows bool dtype in zeros via typed_and_generic

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

  • None

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".

Normal bug identification and options to explore for fixing it.


@stdlib-js/reviewers

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: passed
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
@anandkaranubc anandkaranubc requested a review from a team April 19, 2026 18:51
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Apr 19, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
array/zeros $\color{red}130/132$
$\color{green}+98.48%$
$\color{red}12/13$
$\color{green}+92.31%$
$\color{green}1/1$
$\color{green}+100.00%$
$\color{red}130/132$
$\color{green}+98.48%$

The above coverage report was generated for the changes in this PR.

@anandkaranubc
Copy link
Copy Markdown
Contributor Author

anandkaranubc commented Apr 19, 2026

CI was failing here on @stdlib/array/from-scalar tests. That code path picks the default boolean type (bool) and then calls @stdlib/array/zeros to create a length-1 array.

zeros only allowed numeric typed dtypes plus generic, so it rejected bool and threw a TypeError before any array was built. The failure showed up in the from-scalar tests, but the real mismatch was that zeros did not accept a dtype that the rest of the stack already treats as a normal typed array.

This change updates zeros to use the same dtype family that includes all typed array kinds, adds a direct test for boolean zeros, and updates the docs and types so they match the behavior.

Seems like zeros was meant to also support boolean values:

https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/array/zeros/README.md#examples

cc: @kgryte

@kgryte
Copy link
Copy Markdown
Member

kgryte commented Apr 19, 2026

This is the wrong fix. The actual fix is to replace the call to zeros

out = zeros( 1, dt ); // delegate dtype validation to `zeros`

with a call to array/empty. Zeros is for numerical arrays.

@kgryte kgryte closed this Apr 19, 2026
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Apr 19, 2026
@kgryte kgryte added the Invalid Invalid question, issue, or pull request. label Apr 19, 2026
@anandkaranubc anandkaranubc deleted the fix/array-zeros-bool-dtype branch April 19, 2026 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Invalid Invalid question, issue, or pull request.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants