-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Fixed tm.set_locale
context manager, it could error and leak when category LC_ALL was used
#47570
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
…ategory LC_ALL was used. Fixed pandas-dev#46595
It would be great to add a test reproducing the initial problem, before fixing it. |
…ocale on it_IT and zh_CN runners, as `strict=False`.
…ure/46405_set_locale_bug
… avoid misuses of `getlocale` (see pandas-dev#46595). Added tests.
@jbrockmendel @mroeschke : Please review this very small PR to fix a leakage problem in When the problem was first fixed, then a few tests started to fail on workers it_IT and zh_CN (see https://github.com/pandas-dev/pandas/actions/runs/2597381464). Looking more closely at the problem, I saw that this was tests marked as https://github.com/pandas-dev/pandas/runs/7152086548?check_suite_focus=true#step:7:54
This was actually a good thing: it proves that the fix worked ! I simply added the When this will be merged, we will be able to proceed with PR #46405 so stay tuned :) |
tm.set_locale
context manager, it could error and leak when category LC_ALL was usedtm.set_locale
context manager, it could error and leak when category LC_ALL was used
…ure/46405_set_locale_bug
@@ -291,6 +291,7 @@ def test_to_datetime_format_microsecond(self, cache): | |||
marks=pytest.mark.xfail( | |||
locale.getlocale()[0] in ("zh_CN", "it_IT"), | |||
reason="fail on a CI build with LC_ALL=zh_CN.utf8/it_IT.utf8", | |||
strict=False, |
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 we just remove these xfails entirely?
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.
No, these tests are executed on other workers, and they pass. So they are important :) We should actually try to solve the issue (datetime parsing, separate topic) if we wish to remove the xfail mark
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 we be make the xfail condition more specific? strict=False
is really undesirable
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.
This is already quite specific: the test will be marked as xfail only if locale.getlocale()[0] in ("zh_CN", "it_IT")
. So for all CI workers except the 2 workers zh_CN and it_IT, the tests are actually correctly executed (and they pass)
Note that I did not write this code, it was already there. But since there was a locale leakage bug, the zh_CN and it_IT locale was actually never active (even on the 2 corresponding CI workers) when hitting the code. This is why noone every needed to add the strict=False flag.
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.
It's not clear to me why strict=False
is needed i.e. why does it sometimes pass? Is it because the locale setting isn't threadsafe? If so, these tests can be decorated with @pytest.mark.single_cpu
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.
This is less specific IMO. See below : on test_to_time you use a fails_on_non_english
mark (for readability) but with still a test about zh_CN and it_IT (because for other locales we actually do not know if it would pass or fail, therefore we do not want to use the xfail mark too prematurely). Let me know
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.
I'm okay with strict=False
for now then especially if there's a path to know how we can remove these in the future.
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.
I'm okay with strict=False for now then especially if there's a path to know how we can remove these in the future.
im not clear on what this path is. can you elaborate on this?
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.
solve the issue (datetime parsing, separate topic)
From your investigation @smarie fixing the datetime parsing would allow us to remove the xfail?
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.
Yes, fixing the parsing for these two locales would remove the xfail.
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.
LGTM given the tests passing
thanks @smarie |
Thanks to both of you for the fast review ! |
…hen category LC_ALL was used (pandas-dev#47570)
tm.set_locale
does not correctly set back the initial locale when locale.LC_ALL is used.tm.can_set_locale
is impacted by the leak #46595doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.