Skip to content

Commit

Permalink
chore: fmt document
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovler-Young committed Dec 2, 2024
1 parent 3786d1e commit b331b5f
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/ia_collection_analyzer/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ def transform_data():
elif transform_type == "Numeric Bins":
new_col = pd.qcut(filtered_pd[source_col], num_bins, labels=False)
elif transform_type == "Value Mapping":

def safe_map(x):
# Convert list to tuple for mapping since lists are unhashable
if isinstance(x, list):
Expand All @@ -389,7 +390,7 @@ def safe_map(x):
for source in m["sources"]:
# Handle both string representations of lists and regular values
mapping_dict[source] = m["target"]
if source.startswith('[') and source.endswith(']'):
if source.startswith("[") and source.endswith("]"):
# Also add the actual list/string version
try:
mapping_dict[eval(source)] = m["target"]
Expand All @@ -405,23 +406,31 @@ def safe_map(x):
# Get samples for each mapping
for mapping in st.session_state.mapping_table:
# For each source value in the mapping
for source in mapping['sources']:
matching_rows = filtered_pd[filtered_pd[source_col] == source].head(3)
for source in mapping["sources"]:
matching_rows = filtered_pd[filtered_pd[source_col] == source].head(
1
)
if not matching_rows.empty:
preview_rows.append(matching_rows)

# Get some unmatched samples too
mapped_values = {s for m in st.session_state.mapping_table for s in m['sources']}
unmatched = filtered_pd[~filtered_pd[source_col].isin(mapped_values)].head(1)
mapped_values = {
s for m in st.session_state.mapping_table for s in m["sources"]
}
unmatched = filtered_pd[~filtered_pd[source_col].isin(mapped_values)].head(
1
)
if not unmatched.empty:
preview_rows.append(unmatched)

# Combine samples
preview_df = pd.concat(preview_rows)
preview_df = pd.DataFrame({
preview_df = pd.DataFrame(
{
"Original": preview_df[source_col],
"Transformed": preview_df[source_col].map(safe_map)
})
"Transformed": preview_df[source_col].map(safe_map),
}
)

st.write("Preview showing examples of each mapping:")
st.write(preview_df.T)
Expand Down

0 comments on commit b331b5f

Please sign in to comment.