diff --git a/packages/@ourworldindata/core-table/src/OwidTable.ts b/packages/@ourworldindata/core-table/src/OwidTable.ts index 7e2dbb3d851..529aff908b1 100644 --- a/packages/@ourworldindata/core-table/src/OwidTable.ts +++ b/packages/@ourworldindata/core-table/src/OwidTable.ts @@ -607,30 +607,25 @@ export class OwidTable extends CoreTable { // Give our users a clean CSV of each Grapher. Assumes an Owid Table with entityName. toPrettyCsv( - // useShortNames: boolean = false, activeColumnSlugs: string[] | undefined = undefined ): string { - const activeColumnsDiff: Set = activeColumnSlugs - ? differenceOfSets([ - new Set(this.columnSlugs), - new Set(activeColumnSlugs), - ]) - : new Set() - const columnSlugsToRemove = differenceOfSets([ - activeColumnsDiff, - new Set([ + let table + if (activeColumnSlugs?.length) { + table = this.select([ OwidTableSlugs.year, OwidTableSlugs.day, this.entityNameSlug, - ]), - ]) - return this.dropColumns([ - OwidTableSlugs.entityId, - OwidTableSlugs.time, - OwidTableSlugs.entityColor, - ...columnSlugsToRemove, - ]) + ...activeColumnSlugs, + ]) + } else { + table = this.dropColumns([ + OwidTableSlugs.entityId, + OwidTableSlugs.time, + OwidTableSlugs.entityColor, + ]) + } + return table .sortBy([this.entityNameSlug]) .toCsvWithColumnNames(useShortNames) }