Skip to content

Commit

Permalink
Added the 'placeholder' write_csv func, fixes #1542 (#1603)
Browse files Browse the repository at this point in the history
Added the 'placeholder' write_csv func, fixes #1542
  • Loading branch information
jmao-denver authored Dec 1, 2021
1 parent 280bc14 commit d55c7d9
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 77 deletions.
3 changes: 2 additions & 1 deletion pyintegration/deephaven2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .dherror import DHError
from .constants import SortDirection
from .csv import read as read_csv
from .csv import write as write_csv
from .table import empty_table, time_table

__all__ = ["read_csv", "DHError", "time_table", "empty_table", "SortDirection"]
__all__ = ["read_csv", "write_csv", "DHError", "time_table", "empty_table", "SortDirection"]
2 changes: 1 addition & 1 deletion pyintegration/deephaven2/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dataclasses import dataclass


@dataclass
@dataclass(frozen=True)
class Column:
""" A Column object represents a column in a Deephaven Table. """
name: str
Expand Down
22 changes: 20 additions & 2 deletions pyintegration/deephaven2/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Deephaven table out as a CSV file.
"""
from enum import Enum
from typing import Dict, Any
from typing import Dict, Any, List

import jpy

Expand All @@ -18,6 +18,7 @@
_JInferenceSpecs = jpy.get_type("io.deephaven.csv.InferenceSpecs")
_JTableHeader = jpy.get_type("io.deephaven.qst.table.TableHeader")
_JCharset = jpy.get_type("java.nio.charset.Charset")
_JCsvTools = jpy.get_type("io.deephaven.csv.CsvTools")


class Inference(Enum):
Expand Down Expand Up @@ -112,4 +113,21 @@ def read(path: str,

return Table(j_table=j_table)
except Exception as e:
raise DHError(e, "read_csv failed") from e
raise DHError(e, "read csv failed") from e


def write(table: Table, path: str, cols: List[str] = []) -> None:
""" Write a table to a standard CSV file.
Args:
table (Table): the source table
path (str): the path of the CSV file
cols (List[str]): the names of the columns to be written out
Raises:
DHError
"""
try:
_JCsvTools.writeCsv(table.j_table, False, path, *cols)
except Exception as e:
raise DHError("write csv failed.") from e
Loading

0 comments on commit d55c7d9

Please sign in to comment.