3

How can I fix the warning:

FutureWarning: 'T' is deprecated and will be removed in a future version. Please use 'min' instead of 'T'.
  if median_diff > pd.Timedelta(freq):

In the method below it comes up every time I run it but I am not using a T in my code that I can see:

@staticmethod
def apply_rolling_average_if_needed(df, freq="1min", rolling_window="5min"):
    """ Apply rolling average if time difference between consecutive 
        timestamps is not greater than the specified frequency.
    """

    print("Warning: If data has a one minute or less sampling frequency a rolling average will be automatically applied")
    sys.stdout.flush()

    time_diff = df.index.to_series().diff().iloc[1:]
    
    # Calculate median time difference to avoid being affected by outliers
    median_diff = time_diff.median()

    print(f"Warning: Median time difference between consecutive timestamps is {median_diff}.")
    sys.stdout.flush()

    if median_diff > pd.Timedelta(freq):
        print(f"Warning: Skipping any rolling averaging...")
        sys.stdout.flush()

    else:
        df = df.rolling(rolling_window).mean()
        print(f"Warning: A {rolling_window} rolling average has been applied to the data.")
        sys.stdout.flush()
    return df
5
  • 2
    How are you calling this method? Commented Aug 8, 2024 at 14:59
  • It's being calling with apply_rolling_average_if_needed(frame, freq="1T") (or similar) somewhere Commented Aug 8, 2024 at 15:03
  • 3
    freq="1T" in the call should be freq="1min". Why did you say you're not using T in the code? Commented Aug 8, 2024 at 15:20
  • ah yes thanks @MathiasR.Jessen post and answer if you want I did have apply_rolling_average_if_needed(frame, freq="1T") in my code base Commented Aug 8, 2024 at 19:39
  • 1
    This question should be closed or deleted. Commented Aug 8, 2024 at 20:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.