Skip to content

BUG: Cleanup timedelta offset #23439

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

Merged
merged 2 commits into from
Nov 6, 2018
Merged

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Nov 1, 2018

Fixed to use same unit parsing logic in Timedelta and to_timedelta. Needs to update after #23264 and #23259.

@pep8speaks
Copy link

Hello @sinhrks! Thanks for submitting the PR.

@codecov
Copy link

codecov bot commented Nov 1, 2018

Codecov Report

Merging #23439 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #23439      +/-   ##
==========================================
- Coverage   92.23%   92.23%   -0.01%     
==========================================
  Files         161      161              
  Lines       51197    51189       -8     
==========================================
- Hits        47220    47212       -8     
  Misses       3977     3977
Flag Coverage Δ
#multiple 90.61% <100%> (-0.01%) ⬇️
#single 42.26% <100%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/tools/timedeltas.py 98.18% <100%> (-0.24%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24ab22f...04f3ceb. Read the comment docs.

@@ -6,3 +6,6 @@ from numpy cimport int64_t
cdef int64_t cast_from_unit(object ts, object unit) except? -1
cpdef int64_t delta_to_nanoseconds(delta) except? -1
cpdef convert_to_timedelta64(object ts, object unit)

# Exposed for Timedelta, not intended for outside use.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this cimported by another cython module? If not, doesn’t need to be in the pxd file

@sinhrks sinhrks force-pushed the timedelta_unit branch 2 times, most recently from d55f00c to 3ade6a9 Compare November 2, 2018 01:06
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment, otherwise lgtm.

for i in np.arange(5).tolist()])
tm.assert_index_equal(result, expected)
for wrapper in [np.array, list, pd.Index]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this a parameter (call it box)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, fixed.

@jreback jreback added this to the 0.24.0 milestone Nov 2, 2018
@jreback jreback merged commit 11c0d28 into pandas-dev:master Nov 6, 2018
@jreback
Copy link
Contributor

jreback commented Nov 6, 2018

thanks @sinhrks

@jorisvandenbossche
Copy link
Member

Personally, I think we should make a distinction between which units are accepted for the unit parameter, and which are parsed inside a string.

For parsing a string, it is fine to accept both '15m', '15min', '15minute', '15minutes and '15T'. But for the unit keyword, is it needed to allow this flexibility?
I would say that just the standard units (the numpy ones, as we had now) + maybe the abbreviations as used in our freq strings should be enough no? (so 'm' and 'T')

(and to be clear, the rest of this PR, fixing the inconsistency of what strings are parsed is of course totally fine!)

@sinhrks
Copy link
Member Author

sinhrks commented Nov 13, 2018

@jorisvandenbossche I kept existing behaviour, but it is better to clarify the policy. It should be consistent with period also.

pd.Period('2011-01', freq='min')
# Period('2011-01-01 00:00', 'T')

pd.Period('2011-01', freq='hour')
# ValueError: Invalid frequency: hour

JustinZhengBC pushed a commit to JustinZhengBC/pandas that referenced this pull request Nov 14, 2018
tm9k1 pushed a commit to tm9k1/pandas that referenced this pull request Nov 19, 2018
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pd.Timedelta() cannot process offset alias T while pd.infer_freq() return this format.
5 participants