Skip to content

chore: remove dead code and outdated guards - #4103

Merged
ikrommyd merged 3 commits into
mainfrom
henryiii/python-dead-code
Jul 11, 2026
Merged

ikrommyd merged 3 commits into
mainfrom
henryiii/python-dead-code

Conversation

@henryiii

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Summary

Dead-code removal across 13 files, 155 lines deleted. Each item was verified before deletion.

  • contents/regulararray.py (lines 1558-1567): Removed tostring() fallback in _to_list; ndarray.tostring was removed from NumPy years ago and every supported nplike has tobytes.
  • _util.py (lines 37-41): Same tostring() fallback in the tobytes() helper; simplified to a one-liner.
  • _errors.py (lines 136-137): Removed numpy.__version__.startswith("1.13.") guard; project requires NumPy ≥ 1.21.3 per pyproject.toml.
  • _nplikes/numpy_like.py and types/numpytype.py: Removed if hasattr(numpy, "float16") guards (exists since NumPy 1.6); moved float16 directly into NumpyMetadata class body. The float128/complex256 guards are retained (genuinely platform-dependent).
  • _backends/backend.py and forms/form.py: Replaced Tuple from awkward._typing with builtin tuple[...] (project requires Python ≥ 3.10).
  • _backends/typetracer.py (lines 33-42): Deleted dead TypeTracerBackend._coerce_ufunc_argument; grep confirmed its only reference was its own recursion. Cleaned up now-unused imports.
  • _slicing.py (lines 368-387): Deleted unreachable branch handling an indexed/option node whose content is also indexed/option (returning the item unchanged, which would infinitely recurse). Verified that all five option/indexed Content constructors (IndexedArray, IndexedOptionArray, ByteMaskedArray, BitMaskedArray, UnmaskedArray) raise TypeError when given option/indexed content — making this path structurally impossible.
  • contents/indexedarray.py (lines 746-789): Reduced _unique_index to its effective behavior: Index64(nplike.unique_values(self._index.data)). The original method ignored its index parameter, unconditionally overwrote its initial allocations, and passed the Index wrapper instead of .data to unique_values. Updated the single caller to drop the now-unused argument.
  • contents/recordarray.py (lines 1126-1141): Collapsed byte-identical if/else branches in _pad_none.
  • contents/listarray.py, contents/indexedarray.py, contents/indexedoptionarray.py: Dropped duplicate self._backend.nplike.known_data and self._backend.nplike.known_data self-conjunctions. Dropped duplicate nplike = backend.nplike assignment in indexedoptionarray.py.

Test plan

  • Ran prek -a --quiet — all hooks pass (ruff, mypy, end-of-file fixer auto-corrected, then clean)
  • Ran pytest tests/ -k "unique or pad_none or to_list or slice or typetracer or indexed or record or float16" -q: 873 passed, 58 skipped (skips are missing optional deps: ROOT, numba, JAX, TF, torch)
  • No new test file needed — this is pure dead-code removal

AI assistance: Claude Code (claude-sonnet-4-6), automated multi-agent review

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.86207% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.58%. Comparing base (f8afd80) to head (9d48614).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/awkward/_errors.py 50.00% 7 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/awkward/_backends/backend.py 89.47% <100.00%> (ø)
src/awkward/_backends/typetracer.py 100.00% <100.00%> (+24.13%) ⬆️
src/awkward/_nplikes/numpy_like.py 100.00% <100.00%> (ø)
src/awkward/_util.py 97.72% <100.00%> (+1.06%) ⬆️
src/awkward/contents/indexedarray.py 88.00% <100.00%> (+1.00%) ⬆️
src/awkward/contents/indexedoptionarray.py 89.97% <100.00%> (-0.02%) ⬇️
src/awkward/contents/listarray.py 92.80% <100.00%> (ø)
src/awkward/contents/recordarray.py 86.77% <100.00%> (+0.13%) ⬆️
src/awkward/contents/regulararray.py 90.10% <100.00%> (+0.29%) ⬆️
src/awkward/forms/form.py 90.52% <100.00%> (ø)
... and 2 more

@henryiii
henryiii force-pushed the henryiii/python-dead-code branch from 82484d1 to a955ffe Compare June 11, 2026 19:44
@TaiSakuma TaiSakuma added the type/chore PR title type: chore (set automatically) label Jun 12, 2026
- regulararray.py, _util.py: drop tostring() fallback (removed from NumPy long ago)
- _errors.py: remove numpy 1.13 version guard (requires >=1.21.3)
- numpy_like.py, numpytype.py: move float16 into class body; remove always-true hasattr guard (exists since NumPy 1.6); keep float128/complex256 guards (platform-dependent)
- _backends/backend.py, forms/form.py: replace typing.Tuple with builtin tuple[...] (Python >=3.10)
- _backends/typetracer.py: delete dead _coerce_ufunc_argument (only reference was its own recursion)
- _slicing.py: delete unreachable branch where option/indexed node contains option/indexed content (all five constructors forbid this)
- contents/indexedarray.py: simplify _unique_index to its effective one-liner
- contents/recordarray.py: collapse byte-identical if/else branches in _pad_none
- listarray.py, indexedarray.py, indexedoptionarray.py: drop duplicate known_data self-conjunctions; drop duplicate nplike assignment

Assisted-by: ClaudeCode:claude-sonnet-4-6
@henryiii
henryiii force-pushed the henryiii/python-dead-code branch from a955ffe to c00cf2a Compare July 7, 2026 17:55
Comment thread src/awkward/types/numpytype.py Resolved
@ikrommyd
ikrommyd enabled auto-merge (squash) July 11, 2026 08:57
@ikrommyd
ikrommyd merged commit 60f0bad into main Jul 11, 2026
68 of 71 checks passed
@ikrommyd
ikrommyd deleted the henryiii/python-dead-code branch July 11, 2026 23:19
@github-actions

Copy link
Copy Markdown
Contributor

The documentation preview is ready to be viewed at http://preview.awkward-array.org.s3-website.us-east-1.amazonaws.com/PR4103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/chore PR title type: chore (set automatically)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants