Skip to content

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

Closed
wants to merge 1 commit into from
Closed

CLN: Cleanup ops.py #13605

wants to merge 1 commit into from

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Jul 10, 2016

  • tests added / passed
  • passes git diff upstream/master | flake8 --diff

Cleanup duplicated code paths before fixing some ops related issues.

@sinhrks sinhrks added Numeric Operations Arithmetic, Comparison, and Logical operations Clean labels Jul 10, 2016
@sinhrks sinhrks added this to the 0.19.0 milestone Jul 10, 2016
@codecov-io
Copy link

codecov-io commented Jul 10, 2016

Current coverage is 84.33%

Merging #13605 into master will decrease coverage by <.01%

@@             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          

Powered by Codecov. Last updated by 5605f99...729997b

@@ -264,7 +263,57 @@ def add_flex_arithmetic_methods(cls, flex_arith_method, radd_func=None,
exclude=exclude)


class _TimeOp(object):
class _Op(object):

Copy link
Contributor

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)

Copy link
Member Author

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
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

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

Copy link
Member Author

@sinhrks sinhrks Jul 12, 2016

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

@jorisvandenbossche
Copy link
Member

Looks good! Small comment

@jreback
Copy link
Contributor

jreback commented Jul 12, 2016

thxs!

@jreback jreback closed this in dbd5330 Jul 12, 2016
@sinhrks sinhrks deleted the ops_cln2 branch July 12, 2016 10:58
nateGeorge pushed a commit to nateGeorge/pandas that referenced this pull request Aug 15, 2016
Author: sinhrks <[email protected]>

Closes pandas-dev#13605 from sinhrks/ops_cln2 and squashes the following commits:

729997b [sinhrks] CLN: Cleanup ops.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants