bigroll commited on
Commit
609b2df
·
verified ·
1 Parent(s): 36513a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -71,22 +71,23 @@ MOTHERDUCK_TOKEN = st.secrets["MOTHERDUCK_TOKEN"]
71
  def get_data():
72
  try:
73
  # Connect to MotherDuck using the token
74
- # This creates an in-memory connection that links to the cloud DB
75
  con = duckdb.connect(f'md:?token={MOTHERDUCK_TOKEN}')
76
 
 
77
  query = """
78
- SELECT id, entity, entity_score, domain, title_score, overall_score, created_at
79
  FROM sentiment_analysis
80
  """
81
 
82
- # Execute query and fetch result as a Pandas DataFrame
83
  df = con.sql(query).df()
84
 
85
- # Check if created_at needs conversion (if it's a timestamp/int)
86
- # If MotherDuck returns datetime objects, this line might need adjustment,
87
- # but keeping original logic assuming Unix timestamp storage.
88
- if not pd.api.types.is_datetime64_any_dtype(df["created_at"]):
89
  df["created_at"] = pd.to_datetime(df["created_at"], unit="s")
 
 
90
 
91
  return df
92
  except Exception as e:
 
71
  def get_data():
72
  try:
73
  # Connect to MotherDuck using the token
 
74
  con = duckdb.connect(f'md:?token={MOTHERDUCK_TOKEN}')
75
 
76
+ # Updated query: Removed 'id' based on your schema
77
  query = """
78
+ SELECT entity, entity_score, domain, title_score, overall_score, created_at
79
  FROM sentiment_analysis
80
  """
81
 
 
82
  df = con.sql(query).df()
83
 
84
+ # Robust date handling:
85
+ # If it's numeric (Unix timestamp), convert using unit='s'.
86
+ # If it's already a TIMESTAMP/Datetime object (MotherDuck native), ensure it's standard pandas datetime.
87
+ if pd.api.types.is_numeric_dtype(df["created_at"]):
88
  df["created_at"] = pd.to_datetime(df["created_at"], unit="s")
89
+ else:
90
+ df["created_at"] = pd.to_datetime(df["created_at"])
91
 
92
  return df
93
  except Exception as e: