Skip to content

Commit

Permalink
pandas numpy incompatibily problem solved
Browse files Browse the repository at this point in the history
  • Loading branch information
arcangelo7 committed Sep 28, 2024
1 parent 24eeeda commit 8546cd4
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 237 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.10"]
services:
redis:
image: redis
Expand Down
25 changes: 24 additions & 1 deletion oc_meta/run/merge/group_entities_to_be_merged.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import csv
import os

import pandas as pd
Expand Down Expand Up @@ -105,7 +106,24 @@ def save_grouped_entities(grouped_data, output_dir):
output_file = os.path.join(output_dir, f"{key.split('/')[-1]}.csv")
if len(df) > 1:
print(f"File with multiple rows: {output_file}")
df.to_csv(output_file, index=False)

try:
df.to_csv(output_file, index=False)
except AttributeError as e:
print(f"Error saving file {output_file}: {str(e)}")
print(f"DataFrame info:")
print(df.info())
print(f"DataFrame head:")
print(df.head())

# Try an alternative method to save the CSV
try:
df.to_csv(output_file, index=False, encoding='utf-8', quoting=csv.QUOTE_NONNUMERIC)
print(f"Successfully saved using alternative method: {output_file}")
except Exception as alt_e:
print(f"Alternative method also failed: {str(alt_e)}")
except Exception as e:
print(f"Unexpected error saving file {output_file}: {str(e)}")

def main():
parser = argparse.ArgumentParser(description='Process CSV and group entities based on SPARQL queries.')
Expand All @@ -116,8 +134,13 @@ def main():
args = parser.parse_args()

df = load_csv(args.csv_file_path)
print(f"Loaded CSV file with {len(df)} rows")

grouped_entities = group_entities(df, args.sparql_endpoint)
print(f"Grouped entities into {len(grouped_entities)} groups")

save_grouped_entities(grouped_entities, args.output_dir)
print("Finished saving grouped entities")

if __name__ == "__main__":
main()
Loading

0 comments on commit 8546cd4

Please sign in to comment.