Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLCAXCHZF-61/handles cases where CKAN type guessing is disabled #14

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions ckanext/charts/fetchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@ def fetch_data(self) -> pd.DataFrame:
get_read_engine(),
).drop(columns=["_id", "_full_text"])

# Identify columns that are not datetime
non_datetime_cols = df.select_dtypes(exclude=['datetime']).columns
# Apply numeric conversion only to non-datetime columns
df[non_datetime_cols] = df[non_datetime_cols].apply(pd.to_numeric, errors='ignore').fillna(0)

if "date_time" in df.columns:
# Convert the 'date_time' column to string format in ISO 8601
df['date_time'] = df['date_time'].dt.strftime("%Y-%m-%dT%H:%M:%S")
try:
df['date_time'] = pd.to_datetime(df['date_time'])
# Convert valid dates to ISO format
df['date_time'] = df['date_time'].dt.strftime("%Y-%m-%dT%H:%M:%S")
except (ValueError, TypeError, AttributeError) as e:
# Log the warning and keep the original values if conversion fails
log.warning(f"Warning: Could not convert date_time column: {e}")

# Apply numeric conversion to all columns - it will safely ignore non-numeric values
df = df.apply(pd.to_numeric, errors='ignore').fillna(0)

except (ProgrammingError, UndefinedTable) as e:
raise exception.DataFetchError(
Expand Down
Loading