Skip to content

fill_gaps function gives uninformative Exception in case of frequency error #153

Closed
@AlexMilanor

Description

@AlexMilanor

What happened + What you expected to happen

Thank you a lot for your work! This lib is helping me a lot.

When running the fill_gaps function with a mismatch between time_col and freq(for example, time_col is int but freq is string), it returns a Pandas AttributeError about datetimelike values. It would be better to receive a ValueError about the mismatch between time_col and freq.

Versions / Dependencies

Click to expand utilsforecast - 0.2.11

Reproducible example

import pandas as pd
from utilsforecast.preprocessing import fill_gaps

df = pd.DataFrame({
        'uid': [1, 1, 1, 1, 1, 2, 2, 2, 2],
         'dt': [1, 2, 3, 4, 5, 1, 3, 5, 7],
        'val': [5, 4, 6, 2, 2, 5, 6, 4, 4]
        })

fill_gaps(
    df=df,
    id_col='uid',
    time_col='dt',
    freq='MS',
    start='per_serie',
    end='per_serie'
)

The output is an AttributeError when calling id_time_grid.

File ~/miniconda3/envs/env_time_series/lib/python3.12/site-packages/pandas/core/indexes/accessors.py:643, in CombinedDatetimelikeProperties.__new__(cls, data)
    640 elif isinstance(data.dtype, PeriodDtype):
    641     return PeriodProperties(data, orig)
--> 643 raise AttributeError("Can only use .dt accessor with datetimelike values")

AttributeError: Can only use .dt accessor with datetimelike values

Issue Severity

Low: It annoys or frustrates me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions