HusnaManakkot commited on
Commit
a56e568
1 Parent(s): d6893cb

Update spider.py

Browse files
Files changed (1) hide show
  1. spider.py +16 -22
spider.py CHANGED
@@ -1,24 +1,22 @@
1
- from datasets import load_dataset, Dataset
2
  import pandas as pd
 
3
 
4
- # Step 1: Download your uploaded Spider dataset
5
- my_spider_dataset = load_dataset("HusnaManakkot/new-spider-HM", split='train')
 
6
 
7
- # Step 2: Convert the dataset to a Pandas DataFrame
8
- my_spider_df = pd.DataFrame(my_spider_dataset)
9
-
10
- # Step 3: Add a new row to the DataFrame
11
  new_example = {
12
- 'db_id': 'employee_database', # Replace with the actual database ID
13
- 'query': "SELECT AVG(salary) FROM employees WHERE join_date > '2015-01-01' AND department = 'Marketing';",
14
- 'question': 'What is the average salary of employees who joined after 2015 and work in the Marketing department?',
15
- 'query_toks': ['SELECT', 'AVG', '(', 'salary', ')', 'FROM', 'employees', 'WHERE', 'join_date', '>', "'2015-01-01'", 'AND', 'department', '=', "'Marketing'", ';'],
16
- 'query_toks_no_value': ['SELECT', 'AVG', '(', 'salary', ')', 'FROM', 'employees', 'WHERE', 'join_date', '>', 'VALUE', 'AND', 'department', '=', 'VALUE', ';'],
17
- 'question_toks': ['What', 'is', 'the', 'average', 'salary', 'of', 'employees', 'who', 'joined', 'after', '2015', 'and', 'work', 'in', 'the', 'Marketing', 'department', '?'],
18
  'sql': {
19
- 'select': [(0, [(3, (0, 'salary'))])], # (agg_id, val_unit), agg_id for AVG is 0, val_unit is (column_id, column_name)
20
  'from': {'table_units': [('table_unit', 0)], 'conds': []}, # ('table_unit', table_id), assuming 'employees' is the first table
21
- 'where': [(0, False, [(2, (0, 'join_date')), '>', (1, "'2015-01-01'")]), 'AND', (0, False, [(2, (0, 'department')), '=', (1, "'Marketing'")])],
22
  'groupBy': [],
23
  'having': [],
24
  'orderBy': [],
@@ -28,11 +26,7 @@ new_example = {
28
  'except': None
29
  }
30
  }
 
31
 
32
- my_spider_df = my_spider_df.append(new_example, ignore_index=True)
33
-
34
- # Step 4: Convert the modified DataFrame back to a Hugging Face dataset
35
- modified_spider_dataset = Dataset.from_pandas(my_spider_df)
36
-
37
- # Step 5: Push the modified dataset back to your Hugging Face account
38
- modified_spider_dataset.push_to_hub("HusnaManakkot/new-spider-HM")
 
 
1
  import pandas as pd
2
+ from datasets import Dataset
3
 
4
+ # Step 1: Read the Parquet files
5
+ train_df = pd.read_parquet('train-00000-of-00001.parquet')
6
+ validation_df = pd.read_parquet('validation-00000-of-00001.parquet')
7
 
8
+ # Step 2: Add the new row to the training DataFrame
 
 
 
9
  new_example = {
10
+ 'db_id': 'hr_1', # Replace with the actual database ID
11
+ 'query': "SELECT COUNT(*) FROM employees WHERE department = 'Sales' AND salary > 50000;",
12
+ 'question': 'How many employees in the Sales department have a salary greater than $50,000?',
13
+ 'query_toks': ['SELECT', 'COUNT', '(', '*', ')', 'FROM', 'employees', 'WHERE', 'department', '=', "'Sales'", 'AND', 'salary', '>', '50000', ';'],
14
+ 'query_toks_no_value': ['SELECT', 'COUNT', '(', '*', ')', 'FROM', 'employees', 'WHERE', 'department', '=', 'VALUE', 'AND', 'salary', '>', 'VALUE', ';'],
15
+ 'question_toks': ['How', 'many', 'employees', 'in', 'the', 'Sales', 'department', 'have', 'a', 'salary', 'greater', 'than', '$50,000', '?'],
16
  'sql': {
17
+ 'select': [(0, [(3, (0, '*'))])], # (agg_id, val_unit), agg_id for COUNT is 0, val_unit is (column_id, column_name)
18
  'from': {'table_units': [('table_unit', 0)], 'conds': []}, # ('table_unit', table_id), assuming 'employees' is the first table
19
+ 'where': [(0, False, [(2, (0, 'department')), '=', (1, "'Sales'")]), 'AND', (0, False, [(2, (0, 'salary')), '>', (1, '50000')])],
20
  'groupBy': [],
21
  'having': [],
22
  'orderBy': [],
 
26
  'except': None
27
  }
28
  }
29
+ train_df = train_df.append(new_example, ignore_index=True)
30
 
31
+ # Step 3: Write the modified DataFrame back to Parquet
32
+ train_df.to_parquet('train-00000-of-00001.parquet')