Skip to content
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

years-only in date_range uses current date #6961

Closed
rosnfeld opened this issue Apr 25, 2014 · 11 comments · Fixed by #8672
Closed

years-only in date_range uses current date #6961

rosnfeld opened this issue Apr 25, 2014 · 11 comments · Fixed by #8672
Labels
API Design Datetime Datetime data dtype
Milestone

Comments

@rosnfeld
Copy link
Contributor

I ran this on master current as of 2014-04-20 or so and was surprised as to the result:

In [17]: pd.date_range('2014', '2015', freq='M')
Out[17]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-04-30, ..., 2015-03-31]
Length: 12, Freq: M, Timezone: None

I would have expected that to give me the month-ends in 2014, not a year's worth of month-ends starting from today.

Seems to be related to #3944?

@jreback
Copy link
Contributor

jreback commented Apr 25, 2014

I think this is simply an ambiguity, you can (and should specify the start or end date more fully)

e.g. 20140101

maybe could somehow provide a better inference on the default date though if its a 'partial' date.
feel free to look into it (but I think its the same issue as #3944), so going to close this and copy their

@jreback jreback closed this as completed Apr 25, 2014
@jreback jreback added the Dupe label Apr 25, 2014
@jreback jreback reopened this Apr 25, 2014
@jreback
Copy link
Contributor

jreback commented Apr 25, 2014

sorry..realized the other issue is closed (sort of punted on it). as I said, feel free to try to address.

@jreback jreback added API Design and removed Dupe labels Apr 25, 2014
@jreback jreback added this to the 0.15.0 milestone Apr 25, 2014
@sinhrks
Copy link
Member

sinhrks commented Aug 9, 2014

Going to be covered in #7599.

Result after #7599

The problem is caused by a path which uses today's date as default. Being fixed to use first day of the year (and specifying freq outputs expected result).

pd.date_range('2014', '2015', freq='M')
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2014-01-31, ..., 2014-12-31]
# Length: 12, Freq: M, Timezone: None

pd.date_range('2014', '2015', freq='MS')
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2014-01-01, ..., 2015-01-01]
# Length: 13, Freq: MS, Timezone: None

Other datetime parse function results (for ref)

Single year is parsed as the first day of the year in most function already (not changed by #7599).

pd.tseries.tools.parse_time_string('2014')[0]
# 2014-01-01 00:00:00

pd.tseries.tools.to_datetime('2014')
# 2014-01-01 00:00:00

@rosnfeld
Copy link
Contributor Author

rosnfeld commented Aug 9, 2014

Great! I did some ad-hoc testing on your PR and confirm it works as expected. Thanks!

@jreback
Copy link
Contributor

jreback commented Aug 11, 2014

@sinhrks this also seems to be fixed in current master ? (irrespective of #7599)

@sinhrks
Copy link
Member

sinhrks commented Aug 11, 2014

Ah correct. Maybe caused by #7907 replaces dateutil.parse by _string_to_dts.

Adding an explicit test in #7599 though...

@jreback
Copy link
Contributor

jreback commented Aug 11, 2014

ok, so in #7599 just fix up the release notes if you would

@jreback jreback modified the milestones: 0.15.1, 0.15.0 Aug 11, 2014
@jreback jreback modified the milestones: 0.15.1, 0.15.0 Sep 29, 2014
@rosnfeld
Copy link
Contributor Author

As this seems to be fixed in 0.15.0, should we just close this issue?

@jreback
Copy link
Contributor

jreback commented Oct 29, 2014

really? can u a) see if u can find a refence to an issue which closed this ?

if it works can u put a test that validates?

@rosnfeld
Copy link
Contributor Author

Yes, you were actually the first person to figure this out, in the comments above. I'm guessing it's #7907 that fixed it, as @sinhrks said. I can add a test though.

@jreback
Copy link
Contributor

jreback commented Oct 29, 2014

ahh ok
I think that fixed s big that had it go to dateutil which does the wrong thing (and thus it work)
can u add s test release note and well call it a day
thxs

@jreback jreback modified the milestones: 0.15.1, 0.15.2 Oct 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Datetime Datetime data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants