Skip to content
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
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Change Log

All notable changes to the "pastum" extension will be documented in this file.
# Changelog

<!-- Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. -->

## Development version

### Added

- Markdown table support (thanks to @juarezr)
- TSV and CSV table support (thanks to @juarezr)
- `pastum.libraryDeclaration` configuration option, which allows the user to add library declaration to the pasted dataframe. (#18)
- `pastum.airFormat` configuration option, which allows the user to add comment to skip air formatting in R. (#16)

## [0.2.1] - 2024-11-02

### Added
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
"default": true,
"markdownDescription": "Show the `Pastum: paste as default dataframe` command in the editor context menu *(i.e., right-click menu)*. It will only appear in R, Python, and Julia editors. The dataframe will be pasted according to the specified `pastum.defaultDataframeR` and `pastum.defaultDataframePy`."
},
"pastum.libraryDeclaration": {
"type": "boolean",
"default": true,
"markdownDescription": "Add library declaration to the pasted dataframe. (i.e., `import pandas as pd`) before the pasted dataframe."
},
"pastum.airFormat": {
"type": "boolean",
"default": true,
Expand Down
8 changes: 5 additions & 3 deletions src/paste-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ async function clipboardToJSDataFrame(framework = null) {
*/
function createJSDataFrame(tableData, framework) {
const { headers, data, columnTypes } = tableData;
const config = vscode.workspace.getConfiguration("pastum");
const libraryDeclaration = config.get("libraryDeclaration");
let code = "";

/**
Expand Down Expand Up @@ -100,7 +102,7 @@ function createJSDataFrame(tableData, framework) {
});
code += `};`;
} else if (framework === "polars") {
code = `import pl from "nodejs-polars";\n\n`;
code = libraryDeclaration ? `import pl from "nodejs-polars";\n\n` : "";
code += `const df = pl.DataFrame({\n`;
headers.forEach((header, i) => {
const values = data.map((row) => formatValue(row[i], i)).join(", ");
Expand All @@ -110,7 +112,7 @@ function createJSDataFrame(tableData, framework) {
});
code += `});`;
} else if (framework === "arquero") {
code = `import {table} from "arquero";\n\n`;
code = libraryDeclaration ? `import {table} from "arquero";\n\n` : "";
code += `const df = table({\n`;
headers.forEach((header, i) => {
const values = data.map((row) => formatValue(row[i], i)).join(", ");
Expand All @@ -120,7 +122,7 @@ function createJSDataFrame(tableData, framework) {
});
code += `});`;
} else if (framework === "danfo") {
code = `import * as dfd from "danfojs-node";\n\n`;
code = libraryDeclaration ? `import * as dfd from "danfojs-node";\n\n` : "";
code += `obj_data = {\n`;
headers.forEach((header, i) => {
const values = data.map((row) => formatValue(row[i], i)).join(", ");
Expand Down
9 changes: 5 additions & 4 deletions src/paste-julia.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@ function createJuliaDataFrame(tableData) {
}

const { headers, data, columnTypes } = tableData;
let code = `using DataFrames\n\n`;
const config = vscode.workspace.getConfiguration("pastum");
const libraryDeclaration = config.get("libraryDeclaration");
let code = libraryDeclaration ? `using DataFrames\n\n` : "";

code += `DataFrame(\n`;
headers.forEach((header, i) => {
const values = data.map((row) => formatValue(row[i], i)).join(", ");
code += ` :${header} => [${values}]${
i < headers.length - 1 ? ",\n" : "\n"
}`;
code += ` :${header} => [${values}]${i < headers.length - 1 ? ",\n" : "\n"
}`;
});
code += `)`;

Expand Down
23 changes: 11 additions & 12 deletions src/paste-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ async function clipboardToPyDataFrame(framework = null) {
*/
function createPyDataFrame(tableData, framework) {
const { headers, data, columnTypes } = tableData;
const config = vscode.workspace.getConfiguration("pastum");
const libraryDeclaration = config.get("libraryDeclaration");
let code = "";

/**
Expand All @@ -89,33 +91,30 @@ function createPyDataFrame(tableData, framework) {

// pandas
if (framework === "pandas") {
code = `import pandas as pd\n\n`;
code = libraryDeclaration ? `import pandas as pd\n\n` : "";
code += `pd.DataFrame({\n`;
headers.forEach((header, i) => {
const values = data.map((row) => formatValue(row[i], i)).join(", ");
code += ` "${header}": [${values}]${
i < headers.length - 1 ? ",\n" : "\n"
}`;
code += ` "${header}": [${values}]${i < headers.length - 1 ? ",\n" : "\n"
}`;
});
code += `})`;
} else if (framework === "datatable") {
code = `import datatable as dt\n\n`;
code = libraryDeclaration ? `import datatable as dt\n\n` : "";
code += `dt.Frame({\n`;
headers.forEach((header, i) => {
const values = data.map((row) => formatValue(row[i], i)).join(", ");
code += ` "${header}": [${values}]${
i < headers.length - 1 ? ",\n" : "\n"
}`;
code += ` "${header}": [${values}]${i < headers.length - 1 ? ",\n" : "\n"
}`;
});
code += `})`;
} else if (framework === "polars") {
code = `import polars as pl\n\n`;
code = libraryDeclaration ? `import polars as pl\n\n` : "";
code += `pl.DataFrame({\n`;
headers.forEach((header, i) => {
const values = data.map((row) => formatValue(row[i], i)).join(", ");
code += ` "${header}": [${values}]${
i < headers.length - 1 ? ",\n" : "\n"
}`;
code += ` "${header}": [${values}]${i < headers.length - 1 ? ",\n" : "\n"
}`;
});
code += `})`;
}
Expand Down