File size: 881 Bytes
5445ab9
d2a63cc
 
 
5445ab9
 
 
 
d2a63cc
e4316f1
52419fe
 
 
 
 
 
 
5445ab9
31086ae
 
d2a63cc
31086ae
 
 
5445ab9
31086ae
0bd1b0f
31086ae
 
 
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
from typing import TYPE_CHECKING, List, Union

from graphgen.bases.base_reader import BaseReader

if TYPE_CHECKING:
    import ray
    from ray.data import Dataset


class CSVReader(BaseReader):
    """
    Reader for CSV files.
    Columns:
        - type: The type of the document (e.g., "text", "image", etc.)
        - if type is "text", "content" column must be present.
    """

    def read(self, input_path: Union[str, List[str]]) -> "Dataset":
        """
        Read CSV files and return Ray Dataset.

        :param input_path: Path to CSV file or list of CSV files.
        :return: Ray Dataset containing validated and filtered data.
        """
        import ray

        ds = ray.data.read_csv(input_path, include_paths=True)
        ds = ds.map_batches(self._validate_batch, batch_format="pandas")
        ds = ds.filter(self._should_keep_item)
        return ds