-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support writing pandas DataFrame and Series
- Loading branch information
1 parent
dc8a6e8
commit e832205
Showing
5 changed files
with
132 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pandas as pd | ||
|
||
from pymarketstore.utils import timeseries_data_to_write_request | ||
|
||
from .test_results import btc_array, btc_bytes, btc_df | ||
|
||
|
||
class TestTimeseriesDataToWriteRequest: | ||
def test_np_array(self): | ||
assert timeseries_data_to_write_request(btc_array, 'BTC/1Min/OHLCV') == dict( | ||
column_data=btc_bytes, | ||
column_names=['Epoch', 'Open', 'High', 'Low', 'Close', 'Volume'], | ||
column_types=['i8', 'f8', 'f8', 'f8', 'f8', 'f8'], | ||
length=5, | ||
) | ||
|
||
def test_pd_series_indexed_by_timestamp(self): | ||
series = pd.Series(btc_df.Open, index=btc_df.index) | ||
assert timeseries_data_to_write_request(series, 'BTC/1Min/Open') == dict( | ||
column_data=[btc_bytes[0], btc_bytes[1]], | ||
column_names=['Epoch', 'Open'], | ||
column_types=['i8', 'f8'], | ||
length=5, | ||
) | ||
|
||
def test_pd_series_row_from_df(self): | ||
series = btc_df.iloc[0] | ||
expected_epoch = bytes(memoryview(series.name.to_numpy().astype(dtype='i8') // 10**9)) | ||
assert timeseries_data_to_write_request(series, 'BTC/1Min/OHLCV') == dict( | ||
column_data=[expected_epoch] + [bytes(memoryview(val)) for val in series.array], | ||
column_names=['Epoch', 'Open', 'High', 'Low', 'Close', 'Volume'], | ||
column_types=['i8', 'f8', 'f8', 'f8', 'f8', 'f8'], | ||
length=1, | ||
) | ||
|
||
def test_pd_dataframe(self): | ||
assert timeseries_data_to_write_request(btc_df, 'BTC/1Min/OHLCV') == dict( | ||
column_data=btc_bytes, | ||
column_names=['Epoch', 'Open', 'High', 'Low', 'Close', 'Volume'], | ||
column_types=['i8', 'f8', 'f8', 'f8', 'f8', 'f8'], | ||
length=5, | ||
) |