File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed
Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 11# Changelog
22
3+ ## 0.21.0 - TBD
4+
5+ #### Bug fixes
6+ - Fixed an issue where ` DBNStore.from_bytes ` did not rewind seekable buffers
7+
38## 0.20.0 - 2023-09-21
49
510#### Enhancements
Original file line number Diff line number Diff line change @@ -252,7 +252,12 @@ class MemoryDataSource(DataSource):
252252 """
253253
254254 def __init__ (self , source : BytesIO | bytes | IO [bytes ]):
255- initial_data = source if isinstance (source , bytes ) else source .read ()
255+ if isinstance (source , bytes ):
256+ initial_data = source
257+ else :
258+ source .seek (0 )
259+ initial_data = source .read ()
260+
256261 if len (initial_data ) == 0 :
257262 raise ValueError (
258263 f"Cannot create data source from empty { type (source ).__name__ } " ,
Original file line number Diff line number Diff line change @@ -924,6 +924,24 @@ def test_dbnstore_buffer_long(
924924 with pytest .raises (BentoError ):
925925 dbnstore .to_json (tmp_path / "test.json" )
926926
927+ def test_dbnstore_buffer_rewind (
928+ test_data : Callable [[Schema ], bytes ],
929+ tmp_path : Path ,
930+ ) -> None :
931+ """
932+ Test that creating a DBNStore from a seekable buffer will rewind.
933+ """
934+ # Arrange
935+ dbn_stub_data = (
936+ zstandard .ZstdDecompressor ().stream_reader (test_data (Schema .MBO )).read ()
937+ )
938+
939+ # Act
940+ dbn_bytes = BytesIO ()
941+ dbn_bytes .write (dbn_stub_data )
942+ dbnstore = DBNStore .from_bytes (data = dbn_bytes )
943+
944+ assert len (dbnstore .to_df ()) == 4
927945
928946@pytest .mark .parametrize (
929947 "schema" ,
You can’t perform that action at this time.
0 commit comments