Skip to content

Commit 98a03ca

Browse files
committed
more tweaking of auto type detection methods
1 parent d820da2 commit 98a03ca

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/main/java/com/github/lwhite1/tablesaw/io/CsvReader.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,8 @@ public static Table detectedColumnTypes(String csvFileName, boolean header, char
296296
* @throws IOException
297297
*/
298298
public static String printColumnTypes(String csvFileName, boolean header, char delimiter) throws IOException {
299-
Table t = CsvReader.headerOnly(
300-
CsvReader.detectColumnTypes(csvFileName, header, delimiter), header, delimiter, csvFileName);
301-
Table structure = t.structure();
299+
300+
Table structure = detectedColumnTypes(csvFileName, header, delimiter);
302301

303302
StringBuilder buf = new StringBuilder();
304303

@@ -343,6 +342,12 @@ public static String printColumnTypes(String csvFileName, boolean header, char d
343342
return buf.toString();
344343
}
345344

345+
/**
346+
* Retuns the given file after autodetecting the column types, or trying to
347+
* @param fileName The name of the file to load
348+
* @return A table containing the data from the file
349+
* @throws IOException
350+
*/
346351
public static Table read(String fileName) throws IOException {
347352
ColumnType[] columnTypes = detectColumnTypes(fileName, true, ',');
348353
return read(columnTypes, true, fileName);
@@ -359,6 +364,15 @@ public static Table read(String fileName, boolean header, char delimiter) throws
359364
}
360365

361366
@VisibleForTesting
367+
/**
368+
* Estimates and returns the type for each column in the delimited text file {@code file}
369+
*
370+
* The type is determined by checking a sample of the data in the file. Because only a sample of the data is checked,
371+
* the types may be incorrect. If that is the case a Parse Exception will be thrown.
372+
*
373+
* The method {@code printColumnTypes()} can be used to print a list of the detected columns that can be corrected and
374+
* used to explicitely specify the correct column types.
375+
*/
362376
static ColumnType[] detectColumnTypes(String file, boolean header, char delimiter)
363377
throws IOException {
364378

0 commit comments

Comments
 (0)