Narrow aggregation exception guards to TypeError - #311
Open
vahid-ahmadi wants to merge 1 commit into
Open
Conversation
The six aggregation wrappers wrapped each per-column call in a bare except Exception: pass. The intent (#213) is to skip columns that can't be aggregated, but it also swallowed genuine errors and returned a silently truncated result: d.gini(negatives="bogus") # -> Series([], dtype: object) MicroSeries.gini raises a deliberate ValueError there (#289). Now only TypeError is caught, and the skip is logged at debug level so it stays discoverable. Which columns aggregate is unchanged: non-numeric columns are already filtered by the is_numeric_dtype check above the try. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Closes #304
Problem
The aggregation wrappers in
microdataframe.pywrapped each per-column call in a bareexcept Exception: pass— eight occurrences across_create_scalar_function,_create_vector_function,_create_agnostic_function, and the twoMicroDataFrameGroupByfactories.The intent (#213) is to skip columns that can't be aggregated. But catching everything also discarded genuine errors and handed back a silently truncated result:
MicroSeries.giniraises a deliberate, well-wordedValueErrorfor an unknownnegativesoption (#289). At the DataFrame level it vanished — no traceback, no warning, nothing to say the argument was wrong. The same guard would hide a genuine bug in any weighted statistic.Change
TypeErroronly — the exception a dtype mismatch actually raises.logger.debug("skipping column %s in %s: %s", ...)so a swallowed failure is discoverable.Which columns aggregate does not change: non-numeric columns are already filtered by the
is_numeric_dtypecheck above eachtry. Verified against a frame mixing int, str, bool, and datetime columns — the same columns come back before and after (sum,mean,median,gini,quantile,decile_rank, andgroupby(...).sum()).Verification
ValueErrornow propagates, and non-numeric columns are still skippedmake test— 64 passed on pandas 3.0.5 and pandas 2.3.3Note: the lint job will be red until #307 merges (unrelated ruff 0.16 issue on
main).