| | 556 | |
|---|
| | 557 | def fill_missing_dates(dates, freq=None): |
|---|
| | 558 | """Finds and fills the missing dates in a DateArray. |
|---|
| | 559 | |
|---|
| | 560 | Parameters |
|---|
| | 561 | ---------- |
|---|
| | 562 | dates : {DateArray} |
|---|
| | 563 | Initial array of dates. |
|---|
| | 564 | freq : {freq_spec}, optional |
|---|
| | 565 | Frequency of result. If not specified, the initial frequency is used. |
|---|
| | 566 | """ |
|---|
| | 567 | # Check the frequency ........ |
|---|
| | 568 | orig_freq = freq |
|---|
| | 569 | freq = check_freq(freq) |
|---|
| | 570 | if orig_freq is not None and freq == _c.FR_UND: |
|---|
| | 571 | freqstr = check_freq_str(freq) |
|---|
| | 572 | raise ValueError,\ |
|---|
| | 573 | "Unable to define a proper date resolution (found %s)." % freqstr |
|---|
| | 574 | # Check the dates ............. |
|---|
| | 575 | if not isinstance(dates, DateArray): |
|---|
| | 576 | raise ValueError("expected DateArray, got %s" % type(dates)) |
|---|
| | 577 | |
|---|
| | 578 | if freq != dates.freq: |
|---|
| | 579 | dates = dates.asfreq(freq) |
|---|
| | 580 | |
|---|
| | 581 | if dates.ndim != 1: |
|---|
| | 582 | dates = dates.ravel() |
|---|
| | 583 | if not dates.has_missing_dates(): |
|---|
| | 584 | return dates |
|---|
| | 585 | |
|---|
| | 586 | # ...and now, fill it ! ...... |
|---|
| | 587 | (tstart, tend) = dates[[0,-1]] |
|---|
| | 588 | return date_array(start_date=tstart, end_date=tend) |
|---|
| | 589 | |
|---|
| | 590 | DateArray.fill_missing_dates = fill_missing_dates |
|---|