-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: Cleanup ops.py #13605
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
CLN: Cleanup ops.py #13605
Conversation
Current coverage is 84.33%@@ master #13605 diff @@
==========================================
Files 138 138
Lines 51100 51092 -8
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 43097 43090 -7
+ Misses 8003 8002 -1
Partials 0 0
|
@@ -264,7 +263,57 @@ def add_flex_arithmetic_methods(cls, flex_arith_method, radd_func=None, | |||
exclude=exclude) | |||
|
|||
|
|||
class _TimeOp(object): | |||
class _Op(object): | |||
|
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.
maybe add a doc-string here? (e.g. its purpose and args passed)
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, added.
|
||
index, lidx, ridx = left.index.join(right.index, how='outer', | ||
return_indexers=True) | ||
# convert DatetimeIndex to have UTC |
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 don't understand this comment
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.
Updated the comment to explain below:
If the Series/DataFrame
have different tz, the indexes are converted to UTC (on 0.18.1). Added tests also.
base = pd.DatetimeIndex(['2011-01-01', '2011-01-02', '2011-01-03'], tz='UTC')
idx1 = base.tz_convert('Asia/Tokyo')[:2]
idx2 = base.tz_convert('US/Eastern')[1:]
pd.Series([1, 2], index=idx1) + pd.Series([1, 1], index=idx2)
# 2011-01-01 00:00:00+00:00 NaN
# 2011-01-02 00:00:00+00:00 3.0
# 2011-01-03 00:00:00+00:00 NaN
# dtype: float64
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.
Sorry, still not fully following. Doesn't the alignment already take care of that?
Using your example from above:
In [38]: left = pd.Series([1,2], index=idx1)
In [39]: right = pd.Series([1,2], index=idx2)
In [40]: left, right = left.align(right, copy=False)
In [41]: left.index
Out[41]: DatetimeIndex(['2011-01-01', '2011-01-02', '2011-01-03'], dtype='dateti
me64[ns, UTC]', freq=None)
In [42]: right.index
Out[42]: DatetimeIndex(['2011-01-01', '2011-01-02', '2011-01-03'], dtype='dateti
me64[ns, UTC]', freq=None)
Also, the lidx
and ridx
does not seem to get used here
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.
Ah the example was incorrect. Pls try:
rng = pd.date_range('1/1/2011', periods=3, freq='H', tz='US/Eastern')
ts = pd.Series(np.random.randn(len(rng)), index=rng)
ts_moscow = ts.tz_convert('Europe/Moscow')
# UTC
ts + ts_moscow
# 2011-01-01 05:00:00+00:00 1.284372
# 2011-01-01 06:00:00+00:00 -1.729165
# 2011-01-01 07:00:00+00:00 -1.532616
# Freq: H, dtype: float64
# align doesn't
ts.align(ts_moscow)
# 2011-01-01 00:00:00-05:00 0.642186
# 2011-01-01 01:00:00-05:00 -0.864582
# 2011-01-01 02:00:00-05:00 -0.766308
# Freq: H, dtype: float64
# 2011-01-01 08:00:00+03:00 0.642186
# 2011-01-01 09:00:00+03:00 -0.864582
# 2011-01-01 10:00:00+03:00 -0.766308
# Freq: H, dtype: float64
Looks good! Small comment |
thxs! |
Author: sinhrks <[email protected]> Closes pandas-dev#13605 from sinhrks/ops_cln2 and squashes the following commits: 729997b [sinhrks] CLN: Cleanup ops.py
git diff upstream/master | flake8 --diff
Cleanup duplicated code paths before fixing some ops related issues.