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

Fix: Force index type to str #28

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion data_validation_framework/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,14 @@ def kwargs(self):
def read_dataset(self):
"""Import the dataset to a :class:`pandas.DataFrame`.

Note that the index column is loaded as a string.

This method can be overridden to load custom data (e.g. GeoDataFrame, etc.).
The dataset should always be loaded from the path given by `self.dataset_df`.
"""
return pd.read_csv(self.dataset_df, index_col=self.input_index_col)
return pd.read_csv(
self.dataset_df, index_col=self.input_index_col, dtype={self.input_index_col: str}
)

def pre_process(self, df, args, kwargs):
"""Method executed before applying the external function."""
Expand Down
4 changes: 3 additions & 1 deletion tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,9 @@ def check_exception(failed_task, exception): # pylint: disable=unused-variable
assert not luigi.build([failing_task], local_scheduler=True)

assert failed_tasks == [str(failing_task)]
assert exceptions == [str(IndexError("The following index values are duplicated: [0, 1]"))]
assert exceptions == [
str(IndexError("The following index values are duplicated: ['0', '1']"))
]

def test_change_index(self, tmpdir, TestTask):
dataset_df_path = str(tmpdir / "dataset.csv")
Expand Down