Skip to content

Commit

Permalink
docstring fix; default stream update in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shrshi committed Oct 23, 2023
1 parent 68f80a2 commit 3b8e982
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 35 deletions.
4 changes: 2 additions & 2 deletions cpp/include/cudf/io/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class json_reader_options_builder {
* @endcode
*
* @param options Settings for controlling reading behavior
* @param stream Cuda stream to use for device memory operations
* @param stream CUDA stream used for device memory operations and kernel launches
* @param mr Device memory resource used to allocate device memory of the table in the returned
* table_with_metadata.
*
Expand Down Expand Up @@ -863,7 +863,7 @@ class json_writer_options_builder {
* @endcode
*
* @param options Settings for controlling writing behavior
* @param stream Cuda stream to use for device memory operations
* @param stream CUDA stream used for device memory operations and kernel launches
* @param mr Device memory resource to use for device memory allocation
*/
void write_json(json_writer_options const& options,
Expand Down
6 changes: 4 additions & 2 deletions cpp/tests/io/json_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <cudf_test/column_utilities.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/cudf_gtest.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/iterator_utilities.hpp>
#include <cudf_test/table_utilities.hpp>
#include <cudf_test/type_lists.hpp>
Expand Down Expand Up @@ -1422,8 +1423,9 @@ TEST_F(JsonReaderTest, JsonLongString)
.lines(true)
.na_rep("null");

cudf::io::write_json(
options_builder.build(), cudf::get_default_stream(), rmm::mr::get_current_device_resource());
cudf::io::write_json(options_builder.build(),
cudf::test::get_default_stream(),
rmm::mr::get_current_device_resource());

cudf::table_view const expected = tbl_view;
std::map<std::string, data_type> types;
Expand Down
66 changes: 38 additions & 28 deletions cpp/tests/io/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/iterator_utilities.hpp>

#include <cudf/detail/iterator.cuh>
Expand Down Expand Up @@ -50,15 +51,15 @@ TEST_F(JsonWriterTest, EmptyInput)

// Empty columns in table
cudf::io::write_json(
out_options, cudf::get_default_stream(), rmm::mr::get_current_device_resource());
out_options, cudf::test::get_default_stream(), rmm::mr::get_current_device_resource());
std::string const expected = R"([])";
EXPECT_EQ(expected, std::string(out_buffer.data(), out_buffer.size()));

// Empty columns in table - JSON Lines
out_buffer.clear();
out_options.enable_lines(true);
cudf::io::write_json(
out_options, cudf::get_default_stream(), rmm::mr::get_current_device_resource());
out_options, cudf::test::get_default_stream(), rmm::mr::get_current_device_resource());
std::string const expected_lines = "\n";
EXPECT_EQ(expected_lines, std::string(out_buffer.data(), out_buffer.size()));

Expand All @@ -67,7 +68,7 @@ TEST_F(JsonWriterTest, EmptyInput)
out_options.set_table(tbl_view2);
out_buffer.clear();
cudf::io::write_json(
out_options, cudf::get_default_stream(), rmm::mr::get_current_device_resource());
out_options, cudf::test::get_default_stream(), rmm::mr::get_current_device_resource());
EXPECT_EQ(expected_lines, std::string(out_buffer.data(), out_buffer.size()));
}

Expand All @@ -92,20 +93,22 @@ TEST_F(JsonWriterTest, ErrorCases)
.build();

// not enough column names
EXPECT_THROW(cudf::io::write_json(
out_options, cudf::get_default_stream(), rmm::mr::get_current_device_resource()),
cudf::logic_error);
EXPECT_THROW(
cudf::io::write_json(
out_options, cudf::test::get_default_stream(), rmm::mr::get_current_device_resource()),
cudf::logic_error);

mt.schema_info.emplace_back("int16");
out_options.set_metadata(mt);
EXPECT_NO_THROW(cudf::io::write_json(
out_options, cudf::get_default_stream(), rmm::mr::get_current_device_resource()));
out_options, cudf::test::get_default_stream(), rmm::mr::get_current_device_resource()));

// chunk_rows must be at least 8
out_options.set_rows_per_chunk(0);
EXPECT_THROW(cudf::io::write_json(
out_options, cudf::get_default_stream(), rmm::mr::get_current_device_resource()),
cudf::logic_error);
EXPECT_THROW(
cudf::io::write_json(
out_options, cudf::test::get_default_stream(), rmm::mr::get_current_device_resource()),
cudf::logic_error);
}

TEST_F(JsonWriterTest, PlainTable)
Expand All @@ -127,8 +130,9 @@ TEST_F(JsonWriterTest, PlainTable)
.lines(false)
.na_rep("null");

cudf::io::write_json(
options_builder.build(), cudf::get_default_stream(), rmm::mr::get_current_device_resource());
cudf::io::write_json(options_builder.build(),
cudf::test::get_default_stream(),
rmm::mr::get_current_device_resource());

std::string const expected =
R"([{"col1":"a","col2":"d","int":1,"float":1.5,"int16":null},{"col1":"b","col2":"e","int":2,"float":2.5,"int16":2},{"col1":"c","col2":"f","int":3,"float":3.5,"int16":null}])";
Expand Down Expand Up @@ -158,8 +162,9 @@ TEST_F(JsonWriterTest, SimpleNested)
.lines(true)
.na_rep("null");

cudf::io::write_json(
options_builder.build(), cudf::get_default_stream(), rmm::mr::get_current_device_resource());
cudf::io::write_json(options_builder.build(),
cudf::test::get_default_stream(),
rmm::mr::get_current_device_resource());
std::string const expected = R"({"a":1,"b":2,"c":{"d":3},"f":5.5,"g":[1]}
{"a":6,"b":7,"c":{"d":8},"f":10.5}
{"a":1,"b":2,"c":{"e":4},"f":5.5,"g":[2,null]}
Expand Down Expand Up @@ -191,8 +196,9 @@ TEST_F(JsonWriterTest, MixedNested)
.lines(false)
.na_rep("null");

cudf::io::write_json(
options_builder.build(), cudf::get_default_stream(), rmm::mr::get_current_device_resource());
cudf::io::write_json(options_builder.build(),
cudf::test::get_default_stream(),
rmm::mr::get_current_device_resource());
std::string const expected =
R"([{"a":1,"b":2,"c":{"d":[3]},"f":5.5,"g":[{"h":1}]},)"
R"({"a":6,"b":7,"c":{"d":[8]},"f":10.5},)"
Expand Down Expand Up @@ -226,7 +232,7 @@ TEST_F(JsonWriterTest, WriteReadNested)
.build();

cudf::io::write_json(
out_options, cudf::get_default_stream(), rmm::mr::get_current_device_resource());
out_options, cudf::test::get_default_stream(), rmm::mr::get_current_device_resource());
std::string const expected = R"({"a":1,"b":2,"c":{"d":3},"f":5.5,"g":[1]}
{"a":6,"b":7,"c":{"d":8},"f":10.5}
{"a":1,"b":2,"c":{"e":4},"f":5.5,"g":[2,null]}
Expand Down Expand Up @@ -302,7 +308,7 @@ TEST_F(JsonWriterTest, WriteReadNested)
out_options.set_metadata(mt);
out_buffer.clear();
cudf::io::write_json(
out_options, cudf::get_default_stream(), rmm::mr::get_current_device_resource());
out_options, cudf::test::get_default_stream(), rmm::mr::get_current_device_resource());

in_options = cudf::io::json_reader_options::builder(
cudf::io::source_info{out_buffer.data(), out_buffer.size()})
Expand All @@ -326,7 +332,7 @@ TEST_F(JsonWriterTest, WriteReadNested)
out_options.set_metadata(cudf::io::table_metadata{});
out_buffer.clear();
cudf::io::write_json(
out_options, cudf::get_default_stream(), rmm::mr::get_current_device_resource());
out_options, cudf::test::get_default_stream(), rmm::mr::get_current_device_resource());
in_options = cudf::io::json_reader_options::builder(
cudf::io::source_info{out_buffer.data(), out_buffer.size()})
.lines(true)
Expand Down Expand Up @@ -365,7 +371,7 @@ TEST_F(JsonWriterTest, SpecialChars)
.build();

cudf::io::write_json(
out_options, cudf::get_default_stream(), rmm::mr::get_current_device_resource());
out_options, cudf::test::get_default_stream(), rmm::mr::get_current_device_resource());
std::string const expected = R"({"\"a\"":1,"'b'":"abcd"}
{"\"a\"":6,"'b'":"b\b\f\n\r\t"}
{"\"a\"":1,"'b'":"\"c\""}
Expand Down Expand Up @@ -398,8 +404,9 @@ TEST_F(JsonWriterTest, NullList)
.lines(true)
.na_rep("null");

cudf::io::write_json(
options_builder.build(), cudf::get_default_stream(), rmm::mr::get_current_device_resource());
cudf::io::write_json(options_builder.build(),
cudf::test::get_default_stream(),
rmm::mr::get_current_device_resource());
std::string const expected = R"({"a":[null],"b":[[1,2,3],[null],[null,null,null],[4,null,5]]}
{"a":[2,null,null,3],"b":null}
{"a":[null,null,4],"b":[[2,null],null]}
Expand Down Expand Up @@ -438,8 +445,9 @@ TEST_F(JsonWriterTest, ChunkedNested)
.na_rep("null")
.rows_per_chunk(8);

cudf::io::write_json(
options_builder.build(), cudf::get_default_stream(), rmm::mr::get_current_device_resource());
cudf::io::write_json(options_builder.build(),
cudf::test::get_default_stream(),
rmm::mr::get_current_device_resource());
std::string const expected =
R"({"a":1,"b":-2,"c":{},"e":[{"f":1}]}
{"a":2,"b":-2,"c":{}}
Expand Down Expand Up @@ -495,8 +503,9 @@ TEST_F(JsonWriterTest, StructAllNullCombinations)
.lines(true)
.na_rep("null");

cudf::io::write_json(
options_builder.build(), cudf::get_default_stream(), rmm::mr::get_current_device_resource());
cudf::io::write_json(options_builder.build(),
cudf::test::get_default_stream(),
rmm::mr::get_current_device_resource());
std::string const expected = R"({}
{"e":1}
{"d":1}
Expand Down Expand Up @@ -558,8 +567,9 @@ TEST_F(JsonWriterTest, Unicode)
.lines(true)
.na_rep("null");

cudf::io::write_json(
options_builder.build(), cudf::get_default_stream(), rmm::mr::get_current_device_resource());
cudf::io::write_json(options_builder.build(),
cudf::test::get_default_stream(),
rmm::mr::get_current_device_resource());

std::string const expected =
R"({"col1":"\"\\\/\b\f\n\r\t","col2":"C\u10ae\u226a\u31f3\u434f\u51f9\u6ca6\u738b\u8fbf\u9fb8\ua057\ubbdc\uc2a4\ud3f6\ue4fe\ufd20","int16":null}
Expand Down
8 changes: 5 additions & 3 deletions cpp/tests/streams/io/functions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <cudf_test/base_fixture.hpp>
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/default_stream.hpp>
#include <cudf_test/iterator_utilities.hpp>

#include <string>
Expand All @@ -40,7 +41,7 @@ TEST_F(FunctionsTest, JSONreader)
.lines(true)
.legacy(true);
cudf::io::table_with_metadata result = cudf::io::read_json(
in_options, cudf::get_default_stream(), rmm::mr::get_current_device_resource());
in_options, cudf::test::get_default_stream(), rmm::mr::get_current_device_resource());
}

TEST_F(FunctionsTest, JSONwriter)
Expand All @@ -62,6 +63,7 @@ TEST_F(FunctionsTest, JSONwriter)
.lines(false)
.na_rep("null");

cudf::io::write_json(
options_builder.build(), cudf::get_default_stream(), rmm::mr::get_current_device_resource());
cudf::io::write_json(options_builder.build(),
cudf::test::get_default_stream(),
rmm::mr::get_current_device_resource());
}

0 comments on commit 3b8e982

Please sign in to comment.