-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fix KeyError by adding check for _convert_dates #60539
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Whenever changing behavior, please add tests.
Thank you for the review. Please guide me on which test file would be the most appropriate for adding tests for this change. |
|
@rhshadrach I have added the tests, please check if they are correct. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
pandas/tests/io/test_stata.py
Outdated
writer._convert_dates = {"old_name": "converted_date"} | ||
columns = ["new_name"] | ||
original_columns = ["old_name"] | ||
for c, o in zip(columns, original_columns): | ||
if c != o and o in writer._convert_dates: | ||
writer._convert_dates[c] = writer._convert_dates[o] | ||
del writer._convert_dates[o] | ||
assert writer._convert_dates == {"new_name": "converted_date"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you instead test using the public API - provide a DataFrame with an name that will be changed, and a convert_dates
, then call read_stata
to check the result.
pandas/tests/io/test_stata.py
Outdated
def test_convert_dates_key_handling(tmp_path, version): | ||
temp_file = tmp_path / "test.dta" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the first line of test references the GitHub issue (or PR):
def test_convert_dates_key_handling(tmp_path, version):
# GH#60536
temp_file = tmp_path / "test.dta"
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
Closing as stale. If you're interested in continuing, merge main and address the comments above and we'd be more than happy to reopen! |
Closes #60536
This PR adds a check to prevent a KeyError when renaming columns by ensuring the original column name exists in the _convert_dates dictionary before updating it.