Skip to content

Commit

Permalink
fix dataframe from sql sort by id (#25)
Browse files Browse the repository at this point in the history
* fix dataframe from sql sort by id
  • Loading branch information
ryan-lam authored Oct 30, 2023
1 parent 9a1c309 commit 4631266
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion etl/etl_routemodel/etl_routemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def seed_from_csv(csv_filepath, db_user, db_password, db_host, db_name):

df.index += 1 # Making table 1-indexed
if inspect(engine).has_table("routemodel"):
row_len = pd.read_sql_query(sql="SELECT COUNT(*) FROM routemodel", con=engine)
row_len = pd.read_sql_query(
sql="SELECT COUNT(*) FROM routemodel ORDER BY id ASC", con=engine
)
df.index += row_len.iloc[0, 0]

response = df.to_sql(
Expand Down
4 changes: 3 additions & 1 deletion etl/etl_weather/etl_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def get_routemodel_df(db_user, db_password, db_host, db_name):

if not inspect(engine).has_table("routemodel"):
raise SystemError("routemodel table does not exist in database")
routemodel_df = pd.read_sql_query(sql="SELECT * FROM routemodel", con=engine)
routemodel_df = pd.read_sql_query(
sql="SELECT * FROM routemodel ORDER BY id ASC", con=engine
)
return routemodel_df


Expand Down
4 changes: 3 additions & 1 deletion update_weather_service/update_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def update_weather(db_user, db_password, db_host, db_name, API_KEY, weather_row_

if not inspect(engine).has_table("weather"):
raise SystemError("weather table does not exist in database")
weather_df = pd.read_sql_query(sql="SELECT * FROM weather", con=engine)
weather_df = pd.read_sql_query(
sql="SELECT * FROM weather ORDER BY id ASC", con=engine
)
weather_df.index += 1 # Make it 1-indexed
weather_df_len = len(weather_df) + 1

Expand Down

0 comments on commit 4631266

Please sign in to comment.