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

ENH: make period_range parse strings like '2012-Q1', not just '2012Q1' #9688

Closed
dr-leo opened this issue Mar 20, 2015 · 2 comments · Fixed by #9701
Closed

ENH: make period_range parse strings like '2012-Q1', not just '2012Q1' #9688

dr-leo opened this issue Mar 20, 2015 · 2 comments · Fixed by #9701
Labels
Enhancement Period Period data type
Milestone

Comments

@dr-leo
Copy link
Contributor

dr-leo commented Mar 20, 2015

This format is used, e.g., in datasets from the ECB.

Code example:

In [25]: PD.period_range(start = '2012Q1', periods = 4, freq = 'Q')
Out[25]:
<class 'pandas.tseries.period.PeriodIndex'>
[2012Q1, ..., 2012Q4]
Length: 4, Freq: Q-DEC

In [26]: PD.period_range(start = '2012-Q1', periods = 4, freq = 'Q')

ValueError Traceback (most recent call last)
C:\Users\stefan\Anaconda\envs\py343\lib\site-packages\pandas\tseries\tools.py in
parse_time_string(arg, freq, dayfirst, yearfirst)
463 parsed, reso = dateutil_parse(arg, default, dayfirst=dayfirst,
--> 464 yearfirst=yearfirst)
465 except Exception as e:

C:\Users\stefan\Anaconda\envs\py343\lib\site-packages\pandas\tseries\tools.py in
dateutil_parse(timestr, default, ignoretz, tzinfos, **kwargs)
489 if res is None:
--> 490 raise ValueError("unknown string format")
491

ValueError: unknown string format

During handling of the above exception, another exception occurred:

DateParseError Traceback (most recent call last)
in ()
----> 1 PD.period_range(start = '2012-Q1', periods = 4, freq = 'Q')

C:\Users\stefan\Anaconda\envs\py343\lib\site-packages\pandas\tseries\period.py i
n period_range(start, end, periods, freq, name)
1433 """
1434 return PeriodIndex(start=start, end=end, periods=periods,
-> 1435 freq=freq, name=name)

C:\Users\stefan\Anaconda\envs\py343\lib\site-packages\pandas\tseries\period.py i
n new(cls, data, ordinal, freq, start, end, periods, copy, name, tz, **kwarg
s)
637 else:
638 data, freq = cls._generate_range(start, end, periods,
--> 639 freq, kwargs)
640 else:
641 ordinal, freq = cls._from_arraylike(data, freq, tz)

C:\Users\stefan\Anaconda\envs\py343\lib\site-packages\pandas\tseries\period.py i
n _generate_range(cls, start, end, periods, freq, fields)
651 raise ValueError('Can either instantiate from fields '
652 'or endpoints, but not both')
--> 653 subarr, freq = _get_ordinal_range(start, end, periods, freq)

654         elif field_count > 0:
655             subarr, freq = _range_from_fields(freq=freq, **fields)

C:\Users\stefan\Anaconda\envs\py343\lib\site-packages\pandas\tseries\period.py i
n _get_ordinal_range(start, end, periods, freq)
1281
1282 if start is not None:
-> 1283 start = Period(start, freq)
1284 if end is not None:
1285 end = Period(end, freq)

C:\Users\stefan\Anaconda\envs\py343\lib\site-packages\pandas\tseries\period.py i
n init(self, value, freq, ordinal, year, month, quarter, day, hour, minute,
second)
124 value = value.upper()
125
--> 126 dt, _, reso = parse_time_string(value, freq)
127 if freq is None:
128 try:

C:\Users\stefan\Anaconda\envs\py343\lib\site-packages\pandas\tseries\tools.py in
parse_time_string(arg, freq, dayfirst, yearfirst)
465 except Exception as e:
466 # TODO: allow raise of errors within instead
--> 467 raise DateParseError(e)
468
469 if parsed is None:

DateParseError: unknown string format

@jreback
Copy link
Contributor

jreback commented Mar 20, 2015

seems like a straightforward extension, pull requests welcome!

@jreback jreback added Enhancement Period Period data type labels Mar 20, 2015
@jreback jreback added this to the Next Major Release milestone Mar 20, 2015
@jreback jreback modified the milestones: 0.16.1, Next Major Release Mar 25, 2015
williamhogman added a commit to williamhogman/pandas that referenced this issue Mar 26, 2015
This closes pandas-dev#9688 by making years and quarters separable by dashes.
ssanderson pushed a commit to ssanderson/pandas that referenced this issue Apr 8, 2015
This closes pandas-dev#9688 by making years and quarters separable by dashes.
@dr-leo
Copy link
Contributor Author

dr-leo commented Apr 10, 2015

That's been really fast!

After a quick look at the code I was wondering if it also handels
"2014-S1" for semesters. If "T" for trimersters is also in use, I don't
know. But semesters are. And pandas should parse them as well.

Sorry for not being able to read through the code more thoroughly. I
have been all too busy with my own pet project pandaSDMX wich will be
released in a few days.

Thanks.

Leo

Am 26.03.2015 um 10:50 schrieb jreback:

Closed #9688 #9688 via #9701
#9701.


Reply to this email directly or view it on GitHub
#9688 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants