@@ -937,6 +937,57 @@ def test_dbnstore_to_ndarray_with_count(
937937 assert np .array_equal (expected , np .concatenate (aggregator ))
938938
939939
940+ @pytest .mark .parametrize (
941+ "schema" ,
942+ [
943+ Schema .MBO ,
944+ Schema .MBP_1 ,
945+ Schema .MBP_10 ,
946+ Schema .TRADES ,
947+ Schema .OHLCV_1S ,
948+ Schema .OHLCV_1M ,
949+ Schema .OHLCV_1H ,
950+ Schema .OHLCV_1D ,
951+ Schema .DEFINITION ,
952+ Schema .STATISTICS ,
953+ ],
954+ )
955+ @pytest .mark .parametrize (
956+ "count" ,
957+ [
958+ 1 ,
959+ 2 ,
960+ 3 ,
961+ ],
962+ )
963+ def test_dbnstore_to_ndarray_with_count_live (
964+ schema : Schema ,
965+ live_test_data : bytes ,
966+ count : int ,
967+ ) -> None :
968+ """
969+ Test that calling to_ndarray with count produces an identical result to
970+ without.
971+ """
972+ # Arrange
973+ dbn_stub_data = zstandard .ZstdDecompressor ().stream_reader (live_test_data ).read ()
974+
975+ # Act
976+ dbnstore = DBNStore .from_bytes (data = dbn_stub_data )
977+
978+ expected = dbnstore .to_ndarray (schema = schema )
979+ nd_iter = dbnstore .to_ndarray (schema = schema , count = count )
980+
981+ # Assert
982+ aggregator : list [np .ndarray [Any , Any ]] = []
983+
984+ for batch in nd_iter :
985+ assert len (batch ) <= count
986+ aggregator .append (batch )
987+
988+ assert np .array_equal (expected , np .concatenate (aggregator ))
989+
990+
940991@pytest .mark .parametrize (
941992 "schema" ,
942993 [pytest .param (schema , id = str (schema )) for schema in Schema .variants ()],
@@ -993,6 +1044,38 @@ def test_dbnstore_to_ndarray_with_count_empty(
9931044 assert len (next (nd_iter )) == 0
9941045
9951046
1047+ @pytest .mark .parametrize (
1048+ "schema, expected_count" ,
1049+ [
1050+ (Schema .MBO , 5 ),
1051+ (Schema .MBP_1 , 2 ),
1052+ (Schema .MBP_10 , 2 ),
1053+ (Schema .TRADES , 2 ),
1054+ (Schema .OHLCV_1S , 2 ),
1055+ (Schema .OHLCV_1M , 2 ),
1056+ (Schema .OHLCV_1H , 0 ),
1057+ (Schema .OHLCV_1D , 0 ),
1058+ (Schema .DEFINITION , 2 ),
1059+ (Schema .STATISTICS , 9 ),
1060+ ],
1061+ )
1062+ def test_dbnstore_to_ndarray_with_schema_live (
1063+ live_test_data : bytes ,
1064+ schema : Schema ,
1065+ expected_count : int ,
1066+ ) -> None :
1067+ # Arrange
1068+ dbn_stub_data = zstandard .ZstdDecompressor ().stream_reader (live_test_data ).read ()
1069+
1070+ # Act
1071+ dbnstore = DBNStore .from_bytes (data = dbn_stub_data )
1072+
1073+ array = dbnstore .to_ndarray (schema = schema )
1074+
1075+ # Assert
1076+ assert len (array ) == expected_count
1077+
1078+
9961079def test_dbnstore_to_ndarray_with_schema_empty (
9971080 test_data : Callable [[Dataset , Schema ], bytes ],
9981081) -> None :
@@ -1016,6 +1099,23 @@ def test_dbnstore_to_ndarray_with_schema_empty(
10161099 assert len (array ) == 0
10171100
10181101
1102+ def test_dbnstore_to_ndarray_with_schema_empty_live (
1103+ live_test_data : bytes ,
1104+ ) -> None :
1105+ """
1106+ Test that a schema must be specified for live data.
1107+ """
1108+ # Arrange
1109+ dbn_stub_data = zstandard .ZstdDecompressor ().stream_reader (live_test_data ).read ()
1110+
1111+ # Act
1112+ dbnstore = DBNStore .from_bytes (data = dbn_stub_data )
1113+
1114+ # Assert
1115+ with pytest .raises (ValueError ):
1116+ dbnstore .to_ndarray ()
1117+
1118+
10191119@pytest .mark .parametrize (
10201120 "schema" ,
10211121 [pytest .param (schema , id = str (schema )) for schema in Schema .variants ()],
@@ -1063,32 +1163,38 @@ def test_dbnstore_to_df_with_count(
10631163
10641164
10651165@pytest .mark .parametrize (
1066- "schema" ,
1067- [pytest .param (schema , id = str (schema )) for schema in Schema .variants ()],
1166+ "schema, expected_count" ,
1167+ [
1168+ (Schema .MBO , 5 ),
1169+ (Schema .MBP_1 , 2 ),
1170+ (Schema .MBP_10 , 2 ),
1171+ (Schema .TRADES , 2 ),
1172+ (Schema .OHLCV_1S , 2 ),
1173+ (Schema .OHLCV_1M , 2 ),
1174+ (Schema .OHLCV_1H , 0 ),
1175+ (Schema .OHLCV_1D , 0 ),
1176+ (Schema .DEFINITION , 2 ),
1177+ (Schema .STATISTICS , 9 ),
1178+ ],
10681179)
1069- def test_dbnstore_to_df_with_schema (
1180+ def test_dbnstore_to_df_with_schema_live (
10701181 schema : Schema ,
1071- test_data : Callable [[Dataset , Schema ], bytes ],
1182+ live_test_data : bytes ,
1183+ expected_count : int ,
10721184) -> None :
10731185 """
1074- Test that calling to_df with schema produces an identical result to
1075- without.
1186+ Test that calling to_df with schema produces a DataFrame for live data.
10761187 """
10771188 # Arrange
1078- dbn_stub_data = (
1079- zstandard .ZstdDecompressor ()
1080- .stream_reader (test_data (Dataset .GLBX_MDP3 , schema ))
1081- .read ()
1082- )
1189+ dbn_stub_data = zstandard .ZstdDecompressor ().stream_reader (live_test_data ).read ()
10831190
10841191 # Act
10851192 dbnstore = DBNStore .from_bytes (data = dbn_stub_data )
10861193
1087- expected = dbnstore .to_df ()
1088- actual = dbnstore .to_df (schema = schema )
1194+ df = dbnstore .to_df (schema = schema )
10891195
10901196 # Assert
1091- assert actual . equals ( expected )
1197+ assert len ( df ) == expected_count
10921198
10931199
10941200def test_dbnstore_to_df_with_schema_empty (
0 commit comments