code: def test_calculate_dividend_ratio(self):
      first_date_ix = 200
      dates = self.trading_calendar.all_sessions[
          first_date_ix : first_date_ix + 3
      ]
  
      before_pricing_data = (
          dates[0] - self.trading_calendar.day
      ).tz_convert(None)
      one_day_past_pricing_data = (
          dates[-1] + self.trading_calendar.day
      ).tz_convert(None)
      ten_days_past_pricing_data = (
          dates[-1] + self.trading_calendar.day * 10
      ).tz_convert(None)
  
      def T(n):
          return dates[n].tz_convert(None)
  
      close = pd.DataFrame(
          [
              [10.0, 0.5, 30.0],  # noqa
              [9.5, 0.4, np.nan],  # noqa
              [15.0, 0.6, np.nan],
          ],  # noqa
          columns=[0, 1, 2],
          index=dates,
      )
  
      dividends = pd.DataFrame(
          [
              # ex_date of >=0 means that we cannot get the previous day's
              # close, so we should not expect to see this dividend in the
              # output
              [0, before_pricing_data, 10],
              [0, T(0), 10],
              # previous price was 0.4, meaning the dividend amount
              # is greater than or equal to price and the ratio would be
              # negative. we should warn and drop this row
              [1, T(1), 0.51],
              # previous price was 0.4, meaning the dividend amount
              # is exactly equal to price and the ratio would be 0.
              # we should warn and drop this row
              [1, T(2), 0.4],
              # previous price is nan, so we cannot compute the ratio.
              # we should warn and drop this row
              [2, T(2), 10],
              # previous price was 10, expected ratio is 0.95
              [0, T(1), 0.5],
              # previous price was 0.4, expected ratio is 0.9
              [1, T(2), 0.04],
              # we shouldn't crash in the process of warning/dropping this
              # row even though it is past the range of `dates`
              [2, one_day_past_pricing_data, 0.1],
              [2, ten_days_past_pricing_data, 0.1],
          ],
          columns=["sid", "ex_date", "amount"],
      )
  
      # give every extra date field a unique date so that we can make sure
      # they appear unchanged in the dividends payouts
      ix = first_date_ix
      for col in "declared_date", "record_date", "pay_date":
          extra_dates = self.trading_calendar.all_sessions[
              ix : ix + len(dividends)
          ]
          ix += len(dividends)
          dividends[col] = extra_dates
  
      self.writer_from_close(close).write(dividends=dividends)
      dfs = self.component_dataframes()
      dividend_payouts = dfs.pop("dividend_payouts")
      dividend_ratios = dfs.pop("dividends")
      self.assert_all_empty(dfs)
  
      payout_sort_key = ["sid", "ex_date", "amount"]
      dividend_payouts = dividend_payouts.sort_values(payout_sort_key)
      dividend_payouts = dividend_payouts.reset_index(drop=True)
  
      expected_dividend_payouts = dividend_payouts.sort_values(
          payout_sort_key,
      )
      expected_dividend_payouts = expected_dividend_payouts.reset_index(
          drop=True,
      )
      assert_equal(dividend_payouts, expected_dividend_payouts)
  
      expected_dividend_ratios = pd.DataFrame(
          [[T(1), 0.95, 0], [T(2), 0.90, 1]],
          columns=["effective_date", "ratio", "sid"],
      )
      dividend_ratios = dividend_ratios.sort_values(
          ["effective_date", "sid"],
      )
      dividend_ratios = dividend_ratios.reset_index(drop=True)
      assert_equal(dividend_ratios, expected_dividend_ratios)
  
      self.assertTrue(
          self.log_handler.has_warning(
              "Couldn't compute ratio for dividend sid=2, ex_date=1990-10-18,"
              " amount=10.000",
          )
      )
      self.assertTrue(
          self.log_handler.has_warning(
              "Couldn't compute ratio for dividend sid=2, ex_date=1990-10-19,"
              " amount=0.100",
          )
      )
      self.assertTrue(
          self.log_handler.has_warning(
              "Couldn't compute ratio for dividend sid=2, ex_date=1990-11-01,"
              " amount=0.100",
          )
      )
      self.assertTrue(
          self.log_handler.has_warning(
              "Dividend ratio <= 0 for dividend sid=1, ex_date=1990-10-17,"
              " amount=0.510",
          )
      )
      self.assertTrue(
          self.log_handler.has_warning(
              "Dividend ratio <= 0 for dividend sid=1, ex_date=1990-10-18,"
              " amount=0.400",
          )
      )
  
imports: import logbook
  import numpy
  import pandas
  from zipline.data.adjustments import SQLiteAdjustmentReader, SQLiteAdjustmentWriter
  from zipline.data.in_memory_daily_bars import InMemoryDailyBarReader
  from zipline.testing import parameter_space
  from zipline.testing.predicates import assert_equal
  from zipline.testing.fixtures import WithInstanceTmpDir, WithTradingCalendars, WithLogger, ZiplineTestCase
label_desc: Use image node_id 9 for calling the TestSQLiteAdjustmentsWriter obj's underlying member method code with example usage: obj.test_calculate_dividend_ratio() and returns: dates