Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the 'placeholder' write_csv func, fixes #1542 #1603

Merged
merged 4 commits into from
Dec 1, 2021
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
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