Skip to content

Commit

Permalink
v0.11.4 backports
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper authored Dec 5, 2022
1 parent 5bc0476 commit 332b3e4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/gluonts/dataset/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,18 @@ def pair_with_item_id(obj: Union[Tuple, pd.DataFrame, pd.Series]):
raise ValueError("input must be a pair, or a pandas Series or DataFrame.")


def infer_freq(index: pd.Index):
def infer_freq(index: pd.Index) -> str:
if isinstance(index, pd.PeriodIndex):
return index.freqstr
return pd.infer_freq(index)

freq = pd.infer_freq(index)
# pandas likes to infer the `start of x` frequency, however when doing
# df.to_period("<x>S"), it fails, so we avoid using it. It's enough to
# remove the trailing S, e.g `MS` -> `M
if len(freq) > 1 and freq.endswith("S"):
return freq[:-1]

return freq


def extract_dynamic_array(
Expand Down

0 comments on commit 332b3e4

Please sign in to comment.