Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 53
FIX: executemany RuntimeError when decimals change signs (GH-557)#560
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
Jahnvi Thakkar (jahnvi480)
merged 12 commits into
main
from
jahnvi/fix-executemany-decimal-sign-change-557May 13, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
db0c4d5
Fix executemany RuntimeError when decimals change signs (GH-557)
jahnvi480 813c06d
Optimize GH-557 fix: guard decimal scan with column check, reuse mate…
jahnvi480 2712bf2
Optimize GH-557 fix: guard decimal scan with column check, reuse mate…
jahnvi480 74feb1c
Optimize GH-557 fix: guard decimal scan with column check, reuse mate…
jahnvi480 77bd7ff
Eliminate double scan: compute max decimal formatted len inside _comp…
jahnvi480 71939e8
Merge branch 'main' into jahnvi/fix-executemany-decimal-sign-change-557
jahnvi480 e58e17e
Performing linting
jahnvi480 2eca508
Merge branch 'jahnvi/fix-executemany-decimal-sign-change-557' of http…
jahnvi480 dfdaaf9
Merge branch 'main' into jahnvi/fix-executemany-decimal-sign-change-557
jahnvi480 52ece94
Merge branch 'main' into jahnvi/fix-executemany-decimal-sign-change-557
jahnvi480 ebef56d
Merge branch 'main' into jahnvi/fix-executemany-decimal-sign-change-557
jahnvi480 ffa6987
Refine test docstring for test_executemany_decimal_sign_change
jahnvi480 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2054,19 +2054,27 @@ def _compute_column_type(self, column): | ||
| sample_value: Representative value for type inference and modified_row. | ||
| min_val: Minimum for integers (None otherwise). | ||
| max_val: Maximum for integers (None otherwise). | ||
| max_decimal_formatted_len: Maximum len(format(d, 'f')) across all | ||
| Decimal values in the column (0 when no Decimals are present). | ||
| Used by executemany to correct the SQL_VARCHAR column size when | ||
| the sample value's formatted string is shorter than another | ||
| value's (e.g. positive sample vs negative row value) (GH-557). | ||
| """ | ||
| non_nulls = [v for v in column if v is not None] | ||
| if not non_nulls: | ||
| return None, None, None | ||
| return None, None, None, 0 | ||
| int_values = [v for v in non_nulls if isinstance(v, int)] | ||
| if int_values: | ||
| min_val, max_val = min(int_values), max(int_values) | ||
| sample_value = max(int_values, key=abs) | ||
| return sample_value, min_val, max_val | ||
| return sample_value, min_val, max_val, 0 | ||
| sample_value = None | ||
| max_decimal_formatted_len = 0 | ||
| for v in non_nulls: | ||
| if isinstance(v, decimal.Decimal): | ||
| max_decimal_formatted_len = max(max_decimal_formatted_len, len(format(v, "f"))) | ||
| if not sample_value: | ||
| sample_value = v | ||
| elif isinstance(v, (str, bytes, bytearray)) and isinstance( | ||
| @@ -2120,7 +2128,7 @@ def _compute_column_type(self, column): | ||
| # If comparing Decimal to non-Decimal, prefer Decimal for better type inference | ||
| sample_value = v | ||
| return sample_value, None, None | ||
| return sample_value, None, None, max_decimal_formatted_len | ||
| def executemany( # pylint: disable=too-many-locals,too-many-branches,too-many-statements | ||
| self, operation: str, seq_of_parameters: Union[List[Sequence[Any]], List[Mapping[str, Any]]] | ||
| @@ -2225,7 +2233,7 @@ def executemany( # pylint: disable=too-many-locals,too-many-branches,too-many-s | ||
| if hasattr(seq_of_parameters, "__getitem__") | ||
| else [] | ||
| ) | ||
| sample_value, min_val, max_val = self._compute_column_type(column) | ||
| sample_value, min_val, max_val, _ = self._compute_column_type(column) | ||
| if self._inputsizes and col_index < len(self._inputsizes): | ||
| # Use explicitly set input sizes | ||
| @@ -2301,7 +2309,7 @@ def executemany( # pylint: disable=too-many-locals,too-many-branches,too-many-s | ||
| if hasattr(seq_of_parameters, "__getitem__") | ||
| else [] | ||
| ) | ||
| sample_value, min_val, max_val = self._compute_column_type(column) | ||
| sample_value, min_val, max_val, max_decimal_len = self._compute_column_type(column) | ||
| dummy_row = list(sample_row) | ||
| paraminfo = self._create_parameter_types_list( | ||
| @@ -2322,6 +2330,17 @@ def executemany( # pylint: disable=too-many-locals,too-many-branches,too-many-s | ||
| paraminfo.paramSQLType = ddbc_sql_const.SQL_VARCHAR.value | ||
| paraminfo.columnSize = 1 | ||
| # Correct column size for Decimal columns sent as SQL_VARCHAR (GH-557). | ||
| # The sample value's formatted string may be shorter than another | ||
| # row's (e.g. positive sample "1.0" = 3 chars vs negative "-0.1" = 4). | ||
| # max_decimal_len was already computed during _compute_column_type | ||
| # so no extra iteration is needed. | ||
| if ( | ||
| paraminfo.paramSQLType == ddbc_sql_const.SQL_VARCHAR.value | ||
| and max_decimal_len > paraminfo.columnSize | ||
jahnvi480 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ): | ||
| paraminfo.columnSize = max_decimal_len | ||
| # Special handling for binary data in auto-detected types | ||
| if paraminfo.paramSQLType in ( | ||
| ddbc_sql_const.SQL_BINARY.value, | ||
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.