Skip to content

Commit 12a585c

Browse files
committed
Merge branch 'setfreq' of https://github.com/sinhrks/pandas into sinhrks-setfreq
Conflicts: doc/source/release.rst
2 parents a842853 + 21bdd1e commit 12a585c

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

doc/source/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ Bug Fixes
514514
- Bug in ``PeriodIndex`` partial string slicing (:issue:`6716`)
515515
- Bug in the HTML repr of a truncated Series or DataFrame not showing the class name with the `large_repr` set to 'info'
516516
(:issue:`7105`)
517+
- Bug in ``DatetimeIndex`` specifying ``freq`` raises ``ValueError`` when passed value is too short (:issue:`7098`)
517518

518519
pandas 0.13.1
519520
-------------

pandas/tseries/index.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,10 @@ def __new__(cls, data=None,
299299
if freq is not None and not freq_infer:
300300
inferred = subarr.inferred_freq
301301
if inferred != freq.freqstr:
302-
raise ValueError('Dates do not conform to passed '
303-
'frequency')
302+
on_freq = cls._generate(subarr[0], None, len(subarr), None, freq, tz=tz)
303+
if not np.array_equal(subarr.asi8, on_freq.asi8):
304+
raise ValueError('Inferred frequency {0} from passed dates does not'
305+
'conform to passed frequency {1}'.format(inferred, freq.freqstr))
304306

305307
if freq_infer:
306308
inferred = subarr.inferred_freq

pandas/tseries/tests/test_period.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,11 @@ def test_factorize(self):
23312331
self.assert_numpy_array_equal(arr, exp_arr)
23322332
self.assert_(idx.equals(exp_idx))
23332333

2334+
def test_recreate_from_data(self):
2335+
for o in ['M', 'Q', 'A', 'D', 'B', 'T', 'S', 'L', 'U', 'N', 'H']:
2336+
org = PeriodIndex(start='2001/04/01', freq=o, periods=1)
2337+
idx = PeriodIndex(org.values, freq=o)
2338+
self.assert_(idx.equals(org))
23342339

23352340
def _permute(obj):
23362341
return obj.take(np.random.permutation(len(obj)))

pandas/tseries/tests/test_timeseries.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,28 @@ def test_indexing(self):
285285
# this is a single date, so will raise
286286
self.assertRaises(KeyError, df.__getitem__, df.index[2],)
287287

288+
def test_recreate_from_data(self):
289+
if _np_version_under1p7:
290+
freqs = ['M', 'Q', 'A', 'D', 'B', 'T', 'S', 'L', 'U', 'H']
291+
else:
292+
freqs = ['M', 'Q', 'A', 'D', 'B', 'T', 'S', 'L', 'U', 'H', 'N', 'C']
293+
294+
for f in freqs:
295+
org = DatetimeIndex(start='2001/02/01 09:00', freq=f, periods=1)
296+
idx = DatetimeIndex(org, freq=f)
297+
self.assert_(idx.equals(org))
298+
299+
# unbale to create tz-aware 'A' and 'C' freq
300+
if _np_version_under1p7:
301+
freqs = ['M', 'Q', 'D', 'B', 'T', 'S', 'L', 'U', 'H']
302+
else:
303+
freqs = ['M', 'Q', 'D', 'B', 'T', 'S', 'L', 'U', 'H', 'N']
304+
305+
for f in freqs:
306+
org = DatetimeIndex(start='2001/02/01 09:00', freq=f, tz='US/Pacific', periods=1)
307+
idx = DatetimeIndex(org, freq=f, tz='US/Pacific')
308+
self.assert_(idx.equals(org))
309+
288310

289311
def assert_range_equal(left, right):
290312
assert(left.equals(right))

0 commit comments

Comments
 (0)