fix: assorted operation bugs (softmax, enforce_type, merge_union_of_records, and more)#4107
Open
henryiii wants to merge 3 commits into
Open
fix: assorted operation bugs (softmax, enforce_type, merge_union_of_records, and more)#4107henryiii wants to merge 3 commits into
henryiii wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (96.29%) is below the target coverage (98.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files
|
6e3badd to
eb49445
Compare
…ecords, and more) - ak.softmax: default axis was None, which always raised TypeError; default to axis=-1, update the docstring, and raise a clear error for axis=None. - ak.enforce_type: fix inverted regular->regular enforceability check in _type_is_enforceable (equal sizes now recurse, unequal sizes are rejected), matching _enforce_type. - ak.merge_union_of_records: use the outer union index (layout.index.data) when rewriting indexed/non-indexed union contents, fixing an IndexError on unions containing categorical/indexed records. - ak.argcartesian: honour the requested axis for list inputs (was dropped), matching the dict-input branch. - ak.from_raggedtensor: recurse with count + 1 to avoid RecursionError for tensors with three or more ragged dimensions. - ak.to_parquet_dataset: drop set-literal concatenation in the not-a-directory error (was raising TypeError instead of ValueError). - ak.to_layout: report the invalid string_policy value, not primitive_policy. - ak.count_nonzero: remove duplicated HighLevelContext unwrap block. - ak.to_json: remove no-op 'except Exception as err: raise err from err'. - ak.round / ak.from_safetensors: fix copy-pasted docstring / error message. - ak.unflatten / ak.nan_to_num: yield array-like secondary arguments to the __awkward_function__ dispatch protocol. - ak.from_rdataframe: thread attrs through to the output array. Assisted-by: ClaudeCode:claude-opus-4.8
Assisted-by: ClaudeCode:claude-opus-4.8
- Convert _Dispatcher helper class to _make_dispatch_sentinel() factory function using types.SimpleNamespace + closure - Remove comments that merely restate the surrounding code - Rebase was clean (no conflicts) Assisted-by: ClaudeCode:claude-sonnet-4-6
eb49445 to
82f6ce9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
This batches up a set of small, mostly independent bug fixes in
src/awkward/operations/(plus one in_connect/rdataframe/) found during an automated review.Correctness bugs
ak.softmax(ak_softmax.py): the defaultaxis=Nonealways raisedTypeError(maybe_posaxisdoesaxis >= 0onNone), soak.softmaxnever worked without an explicit axis despite the docstring claimingNonemeant the innermost dimension. Default is nowaxis=-1, the docstring is corrected, andaxis=Noneraises a clearValueError.ak.enforce_type(ak_enforce_type.py): the regular→regular branch of_type_is_enforceablewas inverted — equal sizes reported not enforceable and unequal sizes recursed. Swapped so equal sizes recurse into the content and unequal sizes are rejected, matching_enforce_type. This drives packing decisions in the option/indexed/union paths.ak.merge_union_of_records(ak_merge_union_of_records.py): in the indexed branch the outer union index must come fromlayout.index.data; it was self-indexing the inner content index (content.index.data[content.index.data[...]]), raisingIndexErroron a union containing a categorical/indexed array of records. Now usescontent.index.data[layout.index.data[is_this_tag]](indexed) andlayout.index.data[is_this_tag](non-indexed).ak.argcartesian(ak_argcartesian.py): the list-input branch builtak.local_index(x), dropping the user'saxis, while the dict branch correctly usedak.local_index(x, axis). Now both honouraxis. (Updatedtests/test_2596_named_axis.pyto the now-consistent named-axis output, which matches the dict-input branch.)ak.from_raggedtensor(ak_from_raggedtensor.py):_recursive_callrecursed with the samecount, causingRecursionErrorfor tensors with three or more ragged dimensions. Now passescount + 1.ak.to_parquet_dataset(ak_to_parquet_dataset.py): the not-a-directory error concatenated a set literal (+ {__file__}), raisingTypeErroron that error path. Removed.ak.to_layout(ak_to_layout.py): the invalid-string_policyerror interpolated{primitive_policy!r}; now reports{string_policy!r}.Dispatch-protocol gaps
Third-party
__awkward_function__dispatch never saw array-like secondary arguments:ak.unflatten(ak_unflatten.py): now yieldsarray, counts(countsis array-like).ak.nan_to_num(ak_nan_to_num.py): now also yieldsnan,posinf,neginf.attrsthreadingak.from_rdataframe(ak_from_rdataframe.py,_connect/rdataframe/from_rdataframe.py): documented/acceptedattrs=Nonebut never forwarded it;attrsis now threaded through to the output array the same waybehavioris. (ROOT is unavailable in this environment, so this was fixed by inspection.)Cleanups
ak.count_nonzero(ak_count_nonzero.py): removed a duplicatedHighLevelContextunwrap block.ak.to_json(ak_to_json.py): removed a no-opexcept Exception as err: raise err from errwrapper.ak.round(ak_round.py): replaced a copy-pasted "Returns the real components..." docstring with a correct one-liner.ak.from_safetensors(ak_from_safetensors.py): theImportErrormessage said "to use ak.from_tensorflow"; now saysak.from_safetensors.Tests
A new regression test file covers: softmax default vs. an explicit numpy softmax on a ragged array (and
axis=Noneraising); enforce_type regular-size cases consistent with_type_is_enforceable; merge_union_of_records on a categorical/indexed record union; argcartesian list-vs-dict parity ataxis=1;from_raggedtensor's_recursive_callfor three ragged dimensions; and unflatten/nan_to_num dispatch via a dummy__awkward_function__object.AI assistance
This change was produced with AI assistance (Claude Code, via an automated multi-agent review of the operations module). Fixes were verified by running the new and directly-related existing test suites; the
from_rdataframe,from_raggedtensor, andfrom_safetensorspaths whose optional dependencies (ROOT, TensorFlow) are unavailable locally were addressed by inspection (from_raggedtensor's recursion is additionally covered by a duck-typed unit test).🤖 Generated with Claude Code