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

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

Closed
AlexMilanor opened this issue Feb 20, 2025 · 2 comments · Fixed by #154
Closed

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

AlexMilanor opened this issue Feb 20, 2025 · 2 comments · Fixed by #154
Labels
bug Something isn't working

Comments

@AlexMilanor
Copy link
Contributor

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.

@AlexMilanor AlexMilanor added the bug Something isn't working label Feb 20, 2025
@AlexMilanor
Copy link
Contributor Author

AlexMilanor commented Feb 20, 2025

It seems like it would be simple to implement using validate_freq from the validation module, so I could open a PR if it is ok.

@jmoralez
Copy link
Member

Hey. Yes, adding validate_freq at the top should provide a better error message, feel free to open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants