-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat(python!): Consistently convert to given time zone in Series constructor #16828
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16828 +/- ##
==========================================
- Coverage 81.38% 81.35% -0.03%
==========================================
Files 1425 1425
Lines 187665 187616 -49
Branches 2702 2700 -2
==========================================
- Hits 152725 152638 -87
- Misses 34444 34482 +38
Partials 496 496 ☔ View full report in Codecov by Sentry. |
Can't we add this to the changelog and 1.0 blog? There are more things that change, and raising a warning for every one of them would do more harm (in annoyance) than good I think. I don't think we should warn if behavior changes, but instead of someone does something it shouldn't. |
True...there's already a warning though, it's been there for some time polars/py-polars/polars/_utils/construction/series.py Lines 226 to 235 in c81ef69
It's true that this can be annoying, but I'm also worried about breaking people's code. Other 1.0 changes are louder:
But here, it's a subtle and silent behaviour change, that can be hard to detect. I'd appreciate having a warning in, at least for a little while (say, until 2.0). As much as I like the upgrade guides, I guess that most users ignore them. Up to you of course, just voicing my suggestion, happy to remove it if you agree with the change and prefer to not have the warning |
0858969
to
df380bd
Compare
df380bd
to
c772ec3
Compare
c772ec3
to
5cb989b
Compare
What I don't like about it is that new users or new Polars projects also get this warning and then it is a warning that warns that Polars works the way it works. Which, I think is strange. Can't we add a "migration mode"? Where we add this to the |
I also don't support adding warnings to happy paths. Especially if it's because of legacy reasons from pre-1.0.0. In the future, we could address changes like this over a longer period where we introduce a deprecation warning first. But this is close to be considered a bug (since it's inconsistent across constructors). And this is the 1.0.0 release, so right now is our chance to wipe the slate clean. I will add a section to the migration guide for "sneaky changes that might break your code", and add this one there. I think that'll have to do for this case.
We can do that - we already have something similar with the |
OK, thanks for your reviews 🙏 I've removed the warning then, a
|
Closes #16823
Closes #16297
#16823 (comment) is kinda sending me into an existential crisis. Any decision is going to break code for at least some people. All I can really say is that I wasn't aware of all these different constructors going down different paths when I worked on this.
This PR is one possible solution, and it builds upon #16742
Pros: this addresses quite a few inconsistencies in the constructor logic. With this change, constructing a Series or DataFrame with Python stdlib
date
ordatetime
objects will always convert (not replace) the time zone to the one of the given dtype. Naive objects get converted as if starting from UTC. This also addresses the issue brought up in #16714 (cc @stinodego )Cons: this is a breaking change for anything constructing a Series with a tz-aware dtype and tz-naive datetimes. To try to mitigate damage, a warning is always raised in such cases, with a helpful message indicating what people should do instead, depending on their desired outcome.
Example
Before:
After: