question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pandas.AppendableExcelDataSet doesn't give expected data

See original GitHub issue

Description

pandas.AppendableExcelDataSet doesn’t ensure same data on reload when the same sheet already exists.

Context

Assuming a pipeline uses AppendableExcelDataSet dataset to store preprocessed data in a single sheet, and then merge these in different node downstream. If the sheets with same name already existed before the current run eg: preprocessed_companies, the new data would be saved to sheet preprocessed_companies1. If the new data is different, which is the case when running regularly, the pipeline would keep on using the old dataset or the first dataset.

Steps to Reproduce

Sample script to reproduce a test

from kedro.extras.datasets.pandas import AppendableExcelDataSet
from kedro.extras.datasets.pandas import ExcelDataSet
import pandas as pd

data_1 = pd.DataFrame({"col1": [1, 2], "col2": [4, 5], "col3": [5, 6]})
regular_ds = ExcelDataSet(
    filepath="/tmp/test.xlsx", save_args={"sheet_name": "my_sheet"}
)
regular_ds.save(data_1)


data_2 = pd.DataFrame({"col1": [7, 8], "col2": [5, 7]})
appendable_ds = AppendableExcelDataSet(
    filepath="/tmp/test.xlsx",
    save_args={"sheet_name": "my_sheet"},
    load_args={"sheet_name": "my_sheet"},
)
appendable_ds.save(data_2)
reloaded = appendable_ds.load()

assert data_2.equals(reloaded)

Expected Result

the assert is expected to be true or throw a warning/error stating the sheet already exists

Actual Result

 line 18, in <module>
    assert data_2.equals(reloaded)
AssertionError

Your Environment

Include as many relevant details about the environment in which you experienced the bug:

  • Kedro version used (pip show kedro or kedro -V): kedro, version 0.17.5
  • Python version used (python -V): Python 3.7.9
  • Operating system and version: MacOS BigSur

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
avan-shcommented, Oct 21, 2021

Thanks a lot lorenabalan, Upgrading Pandas version did the trick.

0reactions
lorenabalancommented, Oct 11, 2021

Hi @avan-sh , I’ve tried reproducing using the script you provided, but I get an error at save time, that the sheet already exists. What version of pandas are you running? I see that in 1.3.0 they introduced if_sheet_exists in ExcelWriter which handles the problem you’re encountering.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with missing data — pandas 1.5.2 documentation
Missing data casting rules and indexing​​ While pandas supports storing arrays of integer and boolean type, these types are not capable of storing...
Read more >
Using Pandas and Python to Explore Your Dataset
In this step-by-step tutorial, you'll learn how to start exploring a dataset with Pandas and Python. You'll learn how to access specific rows...
Read more >
How do I create test and train samples from one dataframe ...
Scikit Learn's train_test_split is a good one. It will split both numpy arrays and dataframes. from sklearn.model_selection import train_test_split train, ...
Read more >
Load a pandas DataFrame | TensorFlow Core
If your data has a uniform datatype, or dtype , it's possible to use a pandas DataFrame ... So, to make a dataset...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found