File size: 3,721 Bytes
58cb8a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
"""
Test the wine dataset before uploading to HuggingFace.
This script validates the data quality and structure.
"""

import pandas as pd
from datasets import Dataset, Features, Value

def test_dataset():
    """Test the dataset structure and quality."""

    print("🍷 Testing Wine Text Dataset")
    print("=" * 40)

    # Load the parquet file
    print("πŸ“ Loading dataset...")
    df = pd.read_parquet("wine_text_126k.parquet")

    # Basic structure validation
    print(f"βœ… Dataset loaded: {len(df):,} records")
    print(f"βœ… Columns: {list(df.columns)}")

    # Check schema matches expected
    expected_columns = ['id', 'name', 'description', 'price', 'category', 'region', 'image_id']
    if list(df.columns) == expected_columns:
        print("βœ… Schema matches expected structure")
    else:
        print(f"❌ Schema mismatch. Expected: {expected_columns}")
        return False

    # Data quality checks
    print("\nπŸ“Š Data Quality Report:")

    # Check for missing values
    missing = df.isnull().sum()
    if missing.any():
        print("❌ Missing values found:")
        for col, count in missing.items():
            if count > 0:
                print(f"  {col}: {count:,} missing")
        return False
    else:
        print("βœ… No missing values")

    # Check ID format
    id_pattern_valid = df['id'].str.match(r'^wine_\d{6}$').all()
    if id_pattern_valid:
        print("βœ… ID format is correct (wine_XXXXXX)")
    else:
        print("❌ Invalid ID format found")
        return False

    # Check price range
    price_min, price_max = df['price'].min(), df['price'].max()
    print(f"βœ… Price range: ${price_min:.2f} - ${price_max:.2f}")

    # Check categories
    categories = df['category'].value_counts()
    print(f"βœ… Wine categories ({len(categories)} types):")
    for cat, count in categories.head().items():
        print(f"  {cat}: {count:,}")

    # Check regions
    regions = df['region'].value_counts()
    print(f"βœ… Regions ({len(regions)} types):")
    for region, count in regions.items():
        print(f"  {region}: {count:,}")

    # Test HuggingFace Dataset creation
    print("\nπŸ€— Testing HuggingFace Dataset creation...")
    try:
        features = Features({
            "id": Value("string"),
            "name": Value("string"),
            "description": Value("string"),
            "price": Value("float32"),
            "category": Value("string"),
            "region": Value("string"),
            "image_id": Value("string"),
        })

        dataset = Dataset.from_pandas(df, features=features, preserve_index=False)
        print(f"βœ… HuggingFace Dataset created successfully")
        print(f"βœ… Dataset info: {dataset}")

        # Sample a few records
        print("\nπŸ“‹ Sample records:")
        for i in range(min(3, len(dataset))):
            record = dataset[i]
            print(f"  ID: {record['id']}")
            print(f"  Name: {record['name'][:50]}...")
            print(f"  Price: ${record['price']:.2f}")
            print(f"  Category: {record['category']}")
            print()

        return True

    except Exception as e:
        print(f"❌ HuggingFace Dataset creation failed: {e}")
        return False

if __name__ == "__main__":
    success = test_dataset()

    if success:
        print("πŸŽ‰ All tests passed! Dataset is ready for upload.")
        print("\nπŸ“€ To upload to HuggingFace Hub:")
        print("1. pip install datasets huggingface_hub pyarrow")
        print("2. huggingface-cli login")
        print("3. python upload_to_hf.py --username YOUR_USERNAME")
    else:
        print("❌ Tests failed. Please fix the issues above before uploading.")