Skip to content

Commit d679740

Browse files
authored
bug: Renaming commentChar to commentPrefix (#337)
Renaming commentChar to commentPrefix to match PY-Polars and to close #334 Co-authored-by: Bidek56 <[email protected]>
1 parent bc87999 commit d679740

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

__tests__/io.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ describe("read:csv", () => {
177177
const df2 = pl.readCSV(csv, { dtypes: { a: pl.Utf8 } });
178178
expect(df2.dtypes[0].equals(pl.String)).toBeTruthy();
179179
});
180+
test("csv with commentPrefix", () => {
181+
const df = pl.readCSV(csvpath, { commentPrefix: "vegetables" });
182+
expect(df.shape).toEqual({ height: 20, width: 4 });
183+
});
180184
it.todo("can read from a stream");
181185
});
182186

polars/io.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface ReadCsvOptions {
2323
numThreads: number;
2424
dtypes: Record<string, DataType>;
2525
lowMemory: boolean;
26-
commentChar: string;
26+
commentPrefix: string;
2727
quoteChar: string;
2828
eolChar: string;
2929
nullValues: string | Array<string> | Record<string, string>;
@@ -167,7 +167,7 @@ export function readRecords(
167167
* @param options.dtype -Overwrite the dtypes during inference.
168168
* @param options.schema -Set the CSV file's schema. This only accepts datatypes that are implemented in the csv parser and expects a complete Schema.
169169
* @param options.lowMemory - Reduce memory usage in expense of performance.
170-
* @param options.commentChar - character that indicates the start of a comment line, for instance '#'.
170+
* @param options.commentPrefix - character that indicates the start of a comment line, for instance '#'.
171171
* @param options.quoteChar -character that is used for csv quoting, default = ''. Set to null to turn special handling and escaping of quotes off.
172172
* @param options.nullValues - Values to interpret as null values. You can provide a
173173
* - `string` -> all values encountered equal to this string will be null
@@ -205,7 +205,7 @@ export function readCSV(pathOrBody, options?) {
205205
export interface ScanCsvOptions {
206206
hasHeader: boolean;
207207
sep: string;
208-
commentChar: string;
208+
commentPrefix: string;
209209
quoteChar: string;
210210
skipRows: number;
211211
nullValues: string | Array<string> | Record<string, string>;
@@ -251,7 +251,7 @@ const scanCsvDefaultOptions: Partial<ScanCsvOptions> = {
251251
* @param options.hasHeader - Indicate if first row of dataset is header or not. If set to False first row will be set to `column_x`,
252252
* `x` being an enumeration over every column in the dataset.
253253
* @param options.sep -Character to use as delimiter in the file.
254-
* @param options.commentChar - character that indicates the start of a comment line, for instance '#'.
254+
* @param options.commentPrefix - character that indicates the start of a comment line, for instance '#'.
255255
* @param options.quoteChar -character that is used for csv quoting, default = ''. Set to null to turn special handling and escaping of quotes off.
256256
* @param options.skipRows -Start reading after `skipRows` position.
257257
* @param options.nullValues - Values to interpret as null values. You can provide a
@@ -631,7 +631,7 @@ export function scanIPC(path, options = {}) {
631631
* @param options.numThreads -Number of threads to use in csv parsing. Defaults to the number of physical cpu's of your system.
632632
* @param options.dtype -Overwrite the dtypes during inference.
633633
* @param options.lowMemory - Reduce memory usage in expense of performance.
634-
* @param options.commentChar - character that indicates the start of a comment line, for instance '#'.
634+
* @param options.commentPrefix - character that indicates the start of a comment line, for instance '#'.
635635
* @param options.quoteChar -character that is used for csv quoting, default = ''. Set to null to turn special handling and escaping of quotes off.
636636
* @param options.nullValues - Values to interpret as null values. You can provide a
637637
* - `string` -> all values encountered equal to this string will be null

src/dataframe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct ReadCsvOptions {
6767
pub path: Option<String>,
6868
pub dtypes: Option<HashMap<String, Wrap<DataType>>>,
6969
pub chunk_size: u32,
70-
pub comment_char: Option<String>,
70+
pub comment_prefix: Option<String>,
7171
pub null_values: Option<Wrap<NullValues>>,
7272
pub quote_char: Option<String>,
7373
pub skip_rows_after_header: u32,
@@ -145,7 +145,7 @@ fn mmap_reader_to_df<'a>(
145145
.with_separator(options.sep.unwrap_or(",".to_owned()).as_bytes()[0])
146146
.with_encoding(encoding)
147147
.with_missing_is_null(options.missing_is_null)
148-
.with_comment_prefix(options.comment_char.as_deref())
148+
.with_comment_prefix(options.comment_prefix.as_deref())
149149
.with_null_values(null_values)
150150
.with_try_parse_dates(options.try_parse_dates)
151151
.with_quote_char(quote_char)

0 commit comments

Comments
 (0)