Skip to content

ENH date_range accepts timedelta as freq #6318

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 2 commits into from

Conversation

hayd
Copy link
Contributor

@hayd hayd commented Feb 10, 2014

fixes #6307

@jorisvandenbossche
Copy link
Member

Can you also update the date_range docstring?

@jreback
Copy link
Contributor

jreback commented Feb 10, 2014

you need to fail this if u r on numpy < 1.7 (use pd._np_under_p17); raise that it is not supported (see pd.to_timedelta) for what to do

and skip tests if the same (np.timdelta64 has a diff signature under 1.6)

@hayd
Copy link
Contributor Author

hayd commented Feb 10, 2014

whoops, I had made docstring, but forgot to save that file.

Thanks, will fix up for <1.7.

@hayd
Copy link
Contributor Author

hayd commented Feb 10, 2014

looks like datetime timedelta don't have a total_seconds attribute in 2.6.

@jreback
Copy link
Contributor

jreback commented Feb 10, 2014

yep see my comment in the pr - just pull out the days, seconds and microseconds directly

@jreback
Copy link
Contributor

jreback commented Feb 12, 2014

@hayd any thoughts about not having this always return micro/nano and instead a higher freq if possible?

@jreback jreback added this to the 0.14.0 milestone Feb 12, 2014
@hayd
Copy link
Contributor Author

hayd commented Feb 12, 2014

Yeah, will have another look at this tomorrow.

It begs question should we always be simplifying ticks?

Second(30) + Second(30) == Second(6)  # not Minute(1)

@jreback
Copy link
Contributor

jreback commented Feb 12, 2014

hmm offhand I'll say that the resample code doesn't care whether it's simplified or not (and doesn't make a difference) -

can u give a look. see to see if it matters?

@hayd
Copy link
Contributor Author

hayd commented Feb 12, 2014

resample won't care, will be in the freq repr for the index...

datetime.timedelta does some simplifying think we probably should. sigh, to micros being timedeltas smallest unit, this means the delta attribute does different things for nano and everything else:

In [21]: Nano(1000) == Micro(1)
Out[21]: False

Will fix as part of this...

@jreback
Copy link
Contributor

jreback commented Feb 16, 2014

@hayd ok with merging this like this (after rebase)....then maybe create another issue about the simplification stuff?

@hayd
Copy link
Contributor Author

hayd commented Feb 18, 2014

yea, I refactored this a little already (but not pushed and away atm) so future change should be straightforward. Will do next week.

@jreback
Copy link
Contributor

jreback commented Apr 10, 2014

ping!

@jreback
Copy link
Contributor

jreback commented Apr 21, 2014

ping

@jreback
Copy link
Contributor

jreback commented Apr 27, 2014

moving to 0.15

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Apr 27, 2014
@hayd
Copy link
Contributor Author

hayd commented May 2, 2014

related #5963.

from pandas import _np_version_under1p7
if _np_version_under1p7:
raise nose.SkipTest("date_range with freq timedelta "
"not supported numpy < 1.7")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this may not need to be skipped

@hayd
Copy link
Contributor Author

hayd commented May 2, 2014

I think the pending part of this was comparison of Tickers (previously Nanos(1000) != Micro(1)). Think this should be fixed...

@jreback
Copy link
Contributor

jreback commented May 2, 2014

if u want to go down the rabbit hole
ok (1.6 is really broken though) but do after 0.14

@@ -2783,8 +2783,7 @@ def test_should_cache_week_month(self):

def test_all_cacheableoffsets(self):
for subclass in get_all_subclasses(CacheableOffset):
if subclass.__name__[0] == "_" \
or subclass in TestCaching.no_simple_ctr:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This attribute doesn't seem to exist anywhere... removing looks like it fixes.

@hayd
Copy link
Contributor Author

hayd commented May 28, 2014

Note: docstring doesn't require changing as it already suggests that a timedelta should work.

@jreback jreback added this to the 0.14.1 milestone May 28, 2014
@jreback jreback removed this from the 0.15.0 milestone May 28, 2014
@jreback
Copy link
Contributor

jreback commented May 30, 2014

pls change release notes to v0.14.1 thanks!

@hayd
Copy link
Contributor Author

hayd commented May 30, 2014

added and green (on my travis).

@@ -387,6 +398,38 @@ def get_legacy_offset_name(offset):
name = offset.name
return _legacy_reverse_map.get(name, name)


def _simplify_offset(offset):
Copy link
Contributor

Choose a reason for hiding this comment

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

this is completely internal, yes? any reason to NOT always simplify? (e.g. in to_offset)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to_offset uses offsets._delta_to_tick which also does this simplifying in a similar operation (delta to offset)...

...Ah ha, but to_offset(an_offset) atm is just an_offset, are you suggesting it should return _simplify_offset(an_offset)? This seems reasonable/in line with rest of function.

@jreback
Copy link
Contributor

jreback commented May 30, 2014

I think it makes sense to simply if its unambiguous

@hayd
Copy link
Contributor Author

hayd commented May 30, 2014

agree, done. Also removed some "horrible-ness".

hayd added 2 commits June 13, 2014 18:06
FIX compare ns Ticker with others

FIX remove reference to no_simple_ctr (nowhere else)

DOC move to 0.14.1
@hayd
Copy link
Contributor Author

hayd commented Jun 14, 2014

Hmmm I thought this had already been merged in.

@jreback
Copy link
Contributor

jreback commented Jun 14, 2014

rebase this, and I think you have a 2.6 failing issue

@jreback
Copy link
Contributor

jreback commented Jun 22, 2014

@hayd ?

@jreback jreback modified the milestones: 0.15.0, 0.14.1 Jun 22, 2014
@jreback jreback modified the milestones: 0.15.0, 0.15.1 Jul 6, 2014
@jreback
Copy link
Contributor

jreback commented Jul 21, 2014

@hayd let's revist

@hayd
Copy link
Contributor Author

hayd commented Jul 21, 2014

Sigh, it's only 2.6 that's at issue here (should probably remove the if not _np_version_under1p7 in tests...), I just need to install/build against 2.6 (ahem!)

@jreback
Copy link
Contributor

jreback commented Aug 11, 2014

@hayd ?

@jreback jreback modified the milestones: 0.15.1, 0.15.0 Sep 4, 2014
@jreback
Copy link
Contributor

jreback commented Sep 4, 2014

@hayd ?

@jreback
Copy link
Contributor

jreback commented Jan 18, 2015

closing as stale. @hayd if you'd like to update, pls reopen

@jreback jreback closed this Jan 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Frequency DateOffsets Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

date_range should take timedelta as freq
3 participants