Skip to content
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

Fix actual return type of column_names property #162

Open
wants to merge 1 commit into
base: fix/column-names-for-same-indexset
Choose a base branch
from

Conversation

glatterf42
Copy link
Member

Uncovered another bug introduced by #156 and #157: previously, I returned the column_names property as a cast(list[str], ...) of the underlying sqlalchemy collection. Mypy understood this just fine, but the actual type of the return object was not changed, it was just made to look that way. This created an error in pd.DataFrame().set_index() as this function does not know how to handle sqlalchemy's _AssociationList objects.
This PR fixes this bug by explicitly creating the return object as a list[str]. The for loop should be fine as no item should have more than 12 column_names in practice. It also adds tests to ensure this behaviour doesn't break again in the future.

@glatterf42 glatterf42 added the enhancement New feature or request label Feb 5, 2025
@glatterf42 glatterf42 requested a review from meksor February 5, 2025 07:18
@glatterf42 glatterf42 self-assigned this Feb 5, 2025
@glatterf42 glatterf42 force-pushed the fix/column-names-for-same-indexset branch from 1ceb91e to ef26704 Compare February 5, 2025 10:23
@glatterf42 glatterf42 force-pushed the fix/column-names-property-type branch from 1651ecb to 7ca6c9d Compare February 5, 2025 10:26
Copy link

codecov bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.5%. Comparing base (ef26704) to head (7ca6c9d).

Additional details and impacted files
@@                        Coverage Diff                         @@
##           fix/column-names-for-same-indexset    #162   +/-   ##
==================================================================
  Coverage                                88.5%   88.5%           
==================================================================
  Files                                     223     223           
  Lines                                    8113    8117    +4     
==================================================================
+ Hits                                     7185    7189    +4     
  Misses                                    928     928           
Files with missing lines Coverage Δ
ixmp4/data/db/optimization/equation/model.py 100.0% <100.0%> (ø)
ixmp4/data/db/optimization/parameter/model.py 97.4% <100.0%> (+<0.1%) ⬆️
ixmp4/data/db/optimization/table/model.py 100.0% <100.0%> (ø)
ixmp4/data/db/optimization/variable/model.py 100.0% <100.0%> (ø)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant