code: def test_time_offsets_accuracy(self):
      payload = get_query_context("birth_names")
      payload["queries"][0]["metrics"] = ["sum__num"]
      payload["queries"][0]["groupby"] = ["state"]
      payload["queries"][0]["is_timeseries"] = True
      payload["queries"][0]["timeseries_limit"] = 5
      payload["queries"][0]["time_offsets"] = []
      payload["queries"][0]["time_range"] = "1980 : 1991"
      payload["queries"][0]["granularity"] = "ds"
      payload["queries"][0]["extras"]["time_grain_sqla"] = "P1Y"
      query_context = ChartDataQueryContextSchema().load(payload)
      query_object = query_context.queries[0]
      query_result = query_context.get_query_result(query_object)
      # get main query dataframe
      df = query_result.df
  
      # set time_offsets to query_object
      payload["queries"][0]["time_offsets"] = [
          "3 years ago",
          "3 years later",
      ]
      query_context = ChartDataQueryContextSchema().load(payload)
      query_object = query_context.queries[0]
      time_offsets_obj = query_context.processing_time_offsets(
          df, query_object
      )
      df_with_offsets = time_offsets_obj["df"]
      df_with_offsets = df_with_offsets.set_index(
          ["__timestamp", "state"]
      )
  
      # should get correct data when apply "3 years ago"
      payload["queries"][0]["time_offsets"] = []
      payload["queries"][0]["time_range"] = "1977 : 1988"
      query_context = ChartDataQueryContextSchema().load(payload)
      query_object = query_context.queries[0]
      query_result = query_context.get_query_result(query_object)
      # get df for "3 years ago"
      df_3_years_ago = query_result.df
      df_3_years_ago["__timestamp"] = df_3_years_ago[
          "__timestamp"
      ] + DateOffset(years=3)
      df_3_years_ago = df_3_years_ago.set_index(
          ["__timestamp", "state"]
      )
      for index, row in df_with_offsets.iterrows():
          if index in df_3_years_ago.index:
              assert (
                  row["sum__num__3 years ago"]
                  == df_3_years_ago.loc[index]["sum__num"]
              )
  
      # should get correct data when apply "3 years later"
      payload["queries"][0]["time_offsets"] = []
      payload["queries"][0]["time_range"] = "1983 : 1994"
      query_context = ChartDataQueryContextSchema().load(payload)
      query_object = query_context.queries[0]
      query_result = query_context.get_query_result(query_object)
      # get df for "3 years later"
      df_3_years_later = query_result.df
      df_3_years_later["__timestamp"] = df_3_years_later[
          "__timestamp"
      ] - DateOffset(years=3)
      df_3_years_later = df_3_years_later.set_index(
          ["__timestamp", "state"]
      )
      for index, row in df_with_offsets.iterrows():
          if index in df_3_years_later.index:
              assert (
                  row["sum__num__3 years later"]
                  == df_3_years_later.loc[index]["sum__num"]
              )
  
imports: import re
  import time
  from typing import Any
  import numpy
  import pandas
  import pytest
  from pandas import DateOffset
  from superset import db
  from superset.charts.schemas import ChartDataQueryContextSchema
  from superset.common.chart_data import ChartDataResultFormat, ChartDataResultType
  from superset.common.query_context import QueryContext
  from superset.common.query_context_factory import QueryContextFactory
  from superset.common.query_object import QueryObject
  from superset.connectors.sqla.models import SqlMetric
  from superset.daos.datasource import DatasourceDAO
  from superset.extensions import cache_manager
  from superset.superset_typing import AdhocColumn
  from superset.utils.core import AdhocMetricExpressionType, backend, DatasourceType, QueryStatus
  from superset.utils.pandas_postprocessing.utils import FLAT_COLUMN_SEPARATOR
  from tests.integration_tests.base_tests import SupersetTestCase
  from tests.integration_tests.conftest import only_postgresql, only_sqlite
  from tests.integration_tests.fixtures.birth_names_dashboard import load_birth_names_dashboard_with_slices, load_birth_names_data
  from tests.integration_tests.fixtures.query_context import get_query_context
label_desc: Use image node_id 22 for calling the TestQueryContext obj's underlying member method code with example usage: obj.test_time_offsets_accuracy() without return types