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

Make unique index sorted #855

Merged
merged 1 commit into from
Feb 19, 2024
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
7 changes: 4 additions & 3 deletions src/fondant/components/load_from_csv/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ def _set_unique_index(dataframe: pd.DataFrame, partition_info=None):
Function that sets a unique index
based on the partition and row number.
"""
n_digits = len(str(len(dataframe)))

dataframe["id"] = 1
dataframe["id"] = (
str(partition_info["number"])
+ "_"
+ (dataframe.id.cumsum()).astype(str)
+ dataframe.id.cumsum().astype(str).str.zfill(n_digits)
)
dataframe.index = dataframe.pop("id")
return dataframe
return dataframe.set_index("id", drop=True)

def _get_meta_df() -> pd.DataFrame:
meta_dict = {"id": pd.Series(dtype="object")}
Expand Down
7 changes: 4 additions & 3 deletions src/fondant/components/load_from_hf_hub/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ def set_df_index(self, dask_df: dd.DataFrame) -> dd.DataFrame:

def _set_unique_index(dataframe: pd.DataFrame, partition_info=None):
"""Function that sets a unique index based on the partition and row number."""
n_digits = len(str(len(dataframe)))

dataframe["id"] = 1
dataframe["id"] = (
str(partition_info["number"])
+ "_"
+ (dataframe.id.cumsum()).astype(str)
+ dataframe.id.cumsum().astype(str).str.zfill(n_digits)
)
dataframe.index = dataframe.pop("id")
return dataframe
return dataframe.set_index("id", drop=True)

def _get_meta_df() -> pd.DataFrame:
meta_dict = {"id": pd.Series(dtype="object")}
Expand Down
7 changes: 4 additions & 3 deletions src/fondant/components/load_from_parquet/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ def set_df_index(self, dask_df: dd.DataFrame) -> dd.DataFrame:

def _set_unique_index(dataframe: pd.DataFrame, partition_info=None):
"""Function that sets a unique index based on the partition and row number."""
n_digits = len(str(len(dataframe)))

dataframe["id"] = 1
dataframe["id"] = (
str(partition_info["number"])
+ "_"
+ (dataframe.id.cumsum()).astype(str)
+ dataframe.id.cumsum().astype(str).str.zfill(n_digits)
)
dataframe.index = dataframe.pop("id")
return dataframe
return dataframe.set_index("id", drop=True)

def _get_meta_df() -> pd.DataFrame:
meta_dict = {"id": pd.Series(dtype="object")}
Expand Down
7 changes: 4 additions & 3 deletions src/fondant/components/load_from_pdf/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ def set_df_index(self, dask_df: dd.DataFrame) -> dd.DataFrame:

def _set_unique_index(dataframe: pd.DataFrame, partition_info=None):
"""Function that sets a unique index based on the partition and row number."""
n_digits = len(str(len(dataframe)))

dataframe["id"] = 1
dataframe["id"] = (
str(partition_info["number"])
+ "_"
+ (dataframe.id.cumsum()).astype(str)
+ dataframe.id.cumsum().astype(str).str.zfill(n_digits)
)
dataframe.index = dataframe.pop("id")
return dataframe
return dataframe.set_index("id", drop=True)

def _get_meta_df() -> pd.DataFrame:
meta_dict = {"id": pd.Series(dtype="object")}
Expand Down
Loading