Skip to content

Commit

Permalink
Fix issue trying to enable logs (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd authored Nov 15, 2024
1 parent 626c117 commit 00231a6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/pantab/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,11 @@ auto read_from_hyper_query(
std::unordered_map<std::string, std::string> &&process_params,
size_t chunk_size) -> nb::capsule {

if (!process_params.count("log_config"))
if (!process_params.count("log_config")) {
process_params["log_config"] = "";
} else {
process_params.erase("log_config");
}
if (!process_params.count("default_database_version"))
process_params["default_database_version"] = "2";

Expand Down
5 changes: 4 additions & 1 deletion src/pantab/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,11 @@ void write_to_hyper(
geo_set.insert(colstr);
}

if (!process_params.count("log_config"))
if (!process_params.count("log_config")) {
process_params["log_config"] = "";
} else {
process_params.erase("log_config");
}
if (!process_params.count("default_database_version"))
process_params["default_database_version"] = "2";

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def roundtripped(request):


@pytest.fixture
def tmp_hyper(tmp_path):
def tmp_hyper(tmp_path) -> pathlib.Path:
"""A temporary file name to write / read a Hyper extract from."""
return tmp_path / "test.hyper"

Expand Down
12 changes: 12 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,15 @@ def test_read_batches_without_capsule(tmp_hyper, compat, return_type):
pt.frame_from_hyper(
tmp_hyper, table="test", return_type=return_type, chunk_size=2
)


def test_reader_can_enable_logging(tmp_hyper):
df = pd.DataFrame(list(range(10)), columns=["nums"]).astype("int8")
pt.frame_to_hyper(df, tmp_hyper, table="test")

log_dir = tmp_hyper.parent
params = {"log_config": "enable_me", "log_dir": str(log_dir)}
pt.frame_from_hyper(tmp_hyper, table="test", process_params=params)

assert (log_dir / "hyperd.log").exists()
(log_dir / "hyperd.log").unlink()
11 changes: 11 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,14 @@ def test_writer_invalid_process_params_raises(tmp_hyper):
msg = r"No internal setting named 'not_a_real_parameter'"
with pytest.raises(RuntimeError, match=msg):
pt.frame_to_hyper(frame, tmp_hyper, table="test", process_params=params)


def test_writer_can_enable_logging(tmp_hyper):
tbl = pa.table({"int": pa.array(range(4), type=pa.int16())})

log_dir = tmp_hyper.parent
params = {"log_config": "enable_me", "log_dir": str(log_dir)}
pt.frame_to_hyper(tbl, tmp_hyper, table="test", process_params=params)

assert (log_dir / "hyperd.log").exists()
(log_dir / "hyperd.log").unlink()

0 comments on commit 00231a6

Please sign in to comment.