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

pandas.DeltaTableDataset depends on pyarrow.Table.from_pandas to work properly #610

Open
julio-cmdr opened this issue Feb 29, 2024 · 3 comments

Comments

@julio-cmdr
Copy link

Description

I had some problems with pandas.DeltaTableDataset when my nodes were returning a dataframe. Eg: Running the code below results in the error: name 'sepal_width' present in the specified schema is not found in the columns or index" even with the column sepal_width defined as nullable.

from kedro_datasets.pandas import DeltaTableDataset
import pyarrow as pa

dataset = DeltaTableDataset(
    filepath='data/01_raw/delta_iris',
    save_args={
        'mode': 'overwrite',
        'schema': pa.schema([
            pa.field('sepal_length', pa.float64(), nullable=True),
            pa.field('sepal_width', pa.float64(), nullable=True),
            pa.field('petal_length', pa.float64(), nullable=True),
            pa.field('petal_width', pa.float64(), nullable=True),
            pa.field('species', pa.string(), nullable=False)
        ]),
        'overwrite_schema': True
    }
)

dataset.save(iris.drop(columns=['sepal_width']))

I also had some problems related with index_level_0 column when no schema was specified (see this issue).

Using pyarrow.Table.from_pandas(df) as node return fixed both problems. Could this function be embedded into pandas.DeltaTableDataset in the next release of kedro datasets?

Possible Implementation

Embed pyarrow.Table.from_pandas() inside pandas.DeltaTableDataset.save() function.

Possible Alternatives

Use the pyarrow.Table.from_pandas() function in every node return.

@astrojuanlu
Copy link
Member

Thanks for opening @julio-cmdr . I see you mention the iris dataset, can this be reproduced with something like https://github.com/kedro-org/kedro-starters/tree/main/pandas-iris then?

@julio-cmdr
Copy link
Author

Yeas, I think so! In the example above I just did pd.read_csv() to get the iris dataframe.

@noklam
Copy link
Contributor

noklam commented Mar 5, 2024

regard to index_level_0, I have seen a case that this get created on transcoding from pandas -> spark with parquet. By default pandas.CSVDataset use to_index=False, but this is not consistent for other pandas dataset (ParquetDataset etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants