Skip to content

Commit

Permalink
Merge pull request #128 from umitsarioz/bug-fix-deduplicate
Browse files Browse the repository at this point in the history
bug-fix: removed extra comma when all columns are not defined in dedu…
  • Loading branch information
tgourdel authored Sep 1, 2024
2 parents 364cd82 + ff4b4d7 commit 2bc98ff
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Deduplicate extends BaseCoreComponent {
options: [
{ value: "first", label: "First occurrence", tooltip: "Drop duplicates except for the first occurrence" },
{ value: "last", label: "Last occurrence", tooltip: "Drop duplicates except for the last occurrence" },
{ value: false, label:"Drop all", tooltip: "Drop all duplicates" }
{ value: false, label: "Drop all", tooltip: "Drop all duplicates" }
],
},
{
Expand All @@ -39,11 +39,14 @@ export class Deduplicate extends BaseCoreComponent {
// Initializing code string
let code = `
# Deduplicate rows\n`;
const columns = config.subset.length > 0 ? `subset=[${config.subset.map(column => column.named ? `"${column.value.trim()}"` : column.value).join(', ')}]` : '';

// Ensuring config.subset is defined and has a length property
const subset = config.subset && Array.isArray(config.subset) ? config.subset : [];
const columns = subset.length > 0 ? `subset=[${subset.map(column => column.named ? `"${column.value.trim()}"` : column.value).join(', ')}]` : '';
const keep = typeof config.keep === 'boolean' ? (config.keep ? `"first"` : '') : `"${config.keep}"`;

// Generating the Python code for deduplication
code += `${outputName} = ${inputName}.drop_duplicates(${columns}${keep ? `, keep=${keep}` : ''})\n`;
// Generating the code for deduplication
code += `${outputName} = ${inputName}.drop_duplicates(${columns}${columns && keep ? `, keep=${keep}` : !columns && keep ? `keep=${keep}` : ''})\n`;

return code;
}
Expand Down

0 comments on commit 2bc98ff

Please sign in to comment.