docstr: Tests that replacing a table is possible when: if_replace='replace'.
docstr_tok: ["Tests","that","replacing","a","table","is","possible","when",":","if_replace='replace","'","."]
code: def test_write_postgis_replace_when_table_exists(
      self, engine_postgis, df_nybb
  ):
      """
      Tests that replacing a table is possible when: if_replace='replace'.
      """
      engine = engine_postgis
  
      table = "nybb"
  
      # Ensure table exists
      write_postgis(
          df_nybb, con=engine, name=table, if_exists="replace"
      )
      # Overwrite
      write_postgis(
          df_nybb, con=engine, name=table, if_exists="replace"
      )
      # Validate
      sql = text("SELECT * FROM {table};".format(table=table))
      df = read_postgis(sql, engine, geom_col="geometry")
      validate_boro_df(df)
  
imports: import os
  import warnings
  import pandas
  import geopandas
  from geopandas import GeoDataFrame, read_file, read_postgis
  import geopandas._compat
  from geopandas.io.sql import _get_conn, _write_postgis
  from geopandas.tests.util import create_postgis, create_spatialite, validate_boro_df
  import pytest
label_desc: Use image node_id 17 for calling the TestIO obj's underlying member method code with example usage: obj.test_write_postgis_replace_when_table_exists(engine_postgis, df_nybb) without return types