-
Notifications
You must be signed in to change notification settings - Fork 43
correctly support writing pd.Series and pd.DataFrame #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
briancappello
wants to merge
6
commits into
alpacahq:master
from
briancappello:really-support-pandas-datatypes-in-client-write
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0d3f0d7
correctly support writing pd.Series and pd.DataFrame
briancappello 78b4b7b
add tests
briancappello ccf7072
pandas is py3.5+
briancappello 14f2edd
update readme
briancappello aa2c5ff
support writing pd.Series indexed by timestamp and indexed by column …
briancappello be2c08b
Merge branch 'master' into really-support-pandas-datatypes-in-client-…
briancappello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ Build Status:  | ||
|
|
||
| Tested with 2.7, 3.3+ | ||
| Tested with Python 2.7, 3.5+ | ||
|
|
||
| ## How to install | ||
|
|
||
|
|
@@ -68,43 +68,48 @@ Construct a client object with endpoint. | |
|
|
||
| ## Query | ||
|
|
||
| `pymkts.Client#query(symbols, timeframe, attrgroup, start=None, end=None, limit=None, limit_from_start=False)` | ||
| `pymkts.Client.query(symbols, timeframe, attrgroup, start=None, end=None, limit=None, limit_from_start=False)` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed all of these to dots, feels more "Pythonic" to me, but I'm not especially attached to it either. |
||
|
|
||
| You can build parameters using `pymkts.Params`. | ||
|
|
||
| - symbols: string for a single symbol or a list of symbol string for multi-symbol query | ||
| - timeframe: timeframe string | ||
| - attrgroup: attribute group string. symbols, timeframe and attrgroup compose a bucket key to query in the server | ||
| - start: unix epoch second (int), datetime object or timestamp string. The result will include only data timestamped equal to or after this time. | ||
| - end: unix epoch second (int), datetime object or timestamp string. The result will include only data timestamped equal to or before this time. | ||
| - limit: the number of records to be returned, counting from either start or end boundary. | ||
| - limit_from_start: boolean to indicate `limit` is from the start boundary. Defaults to False. | ||
| - `symbols`: string for a single symbol or a list of symbol string for multi-symbol query | ||
| - `timeframe`: timeframe string | ||
| - `attrgroup`: attribute group string. symbols, timeframe and attrgroup compose a bucket key to query in the server | ||
| - `start`: unix epoch second (int), datetime object or timestamp string. The result will include only data timestamped equal to or after this time. | ||
| - `end`: unix epoch second (int), datetime object or timestamp string. The result will include only data timestamped equal to or before this time. | ||
| - `limit`: the number of records to be returned, counting from either start or end boundary. | ||
| - `limit_from_start`: boolean to indicate `limit` is from the start boundary. Defaults to `False`. | ||
|
|
||
| Pass one or multiple instances of `Params` to `Client.query()`. It will return `QueryReply` object which holds internal numpy array data returned from the server. | ||
|
|
||
| ## Write | ||
|
|
||
| `pymkts.Client#write(data, tbk)` | ||
| `pymkts.Client.write(data, tbk)` | ||
|
|
||
| You can write a numpy array to the server via `Client.write()` method. The data parameter must be numpy's [recarray type](https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.recarray.html) with | ||
| a column named `Epoch` in int64 type at the first column. `tbk` is the bucket key of the data records. | ||
| You can write data to the server via `Client.write()` method. | ||
|
|
||
| - `data`: Timeseries data to write. The supported data types you can write are: | ||
| - [np.recarray](https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.recarray.html) with the first column named `Epoch` in int64 type | ||
| - [pd.Series](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html) with an int64 type index named `Epoch` | ||
| - [pd.DataFrame](https://pandas.pydata.org/pandas-docs/stable/reference/frame.html) with an int64 type index named `Epoch` | ||
| - `tbk`: the bucket key (as a string) of the data records. | ||
|
|
||
| ## List Symbols | ||
|
|
||
| `pymkts.Client#list_symbols()` | ||
| `pymkts.Client.list_symbols()` | ||
|
|
||
| The list of all symbols stored in the server are returned. | ||
|
|
||
| ## Server version | ||
|
|
||
| `pymkts.Client#server_version()` | ||
| `pymkts.Client.server_version()` | ||
|
|
||
| Returns a string of Marketstore-Version header from a server response. | ||
|
|
||
| ## Streaming | ||
|
|
||
| If the server supports WebSocket streaming, you can connect to it using | ||
| `pymkts.StreamConn` class. For convenience, you can call `pymkts.Client#stream()` to obtain the instance with the same server | ||
| `pymkts.StreamConn` class. For convenience, you can call `pymkts.Client.stream()` to obtain the instance with the same server | ||
| information as REST client. | ||
|
|
||
| Once you have this instance, you will set up some event handles by | ||
|
|
@@ -115,24 +120,24 @@ To actually connect and start receiving the messages from the server, | |
| you will call `run()` with the stream names. By default, it subscribes | ||
| to all by `*/*/*`. | ||
|
|
||
| `pymkts.Client#stream()` | ||
| `pymkts.Client.stream()` | ||
|
|
||
| Return a `StreamConn` which is a websocket connection to the server. | ||
|
|
||
| `pymkts.StreamConn#(endpoint)` | ||
| `pymkts.StreamConn(endpoint)` | ||
|
|
||
| Create a connection instance to the `endpoint` server. The endpoint | ||
| string is a full URL with "ws" or "wss" scheme with the port and path. | ||
|
|
||
| `pymkts.StreamConn#register(stream_path, func)` | ||
| `@pymkts.StreamConn#on(stream_path)` | ||
| `pymkts.StreamConn.register(stream_path, func)` | ||
| `@pymkts.StreamConn.on(stream_path)` | ||
|
|
||
| Add a new message handler to the connection. The function will be called | ||
| with `handler(StreamConn, {"key": "...", "data": {...,}})` if the key | ||
| (time bucket key) matches with the `stream_path` regular expression. | ||
| The `on` method is a decorator version of `register`. | ||
|
|
||
| `pymkts.StreamConn#run([stream1, stream2, ...])` | ||
| `pymkts.StreamConn.run([stream1, stream2, ...])` | ||
|
|
||
| Start communication with the server and go into an indefinite loop. It | ||
| does not return until unhandled exception is raised, in which case the | ||
|
|
@@ -154,4 +159,4 @@ def on_btc(conn, msg): | |
| conn.run(['BTC/*/*']) # runs until exception | ||
|
|
||
| -> received btc {'Open': 4370.0, 'High': 4372.93, 'Low': 4370.0, 'Close': 4371.74, 'Volume': 3.3880948699999993, 'Epoch': 1507299600} | ||
| ``` | ||
| ``` | ||
This file contains hidden or 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 hidden or 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,4 @@ | ||
| -r requirements.txt | ||
|
|
||
| pytest | ||
| pytest-cov |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -4,6 +4,5 @@ pandas | |
| requests | ||
| six | ||
| urllib3 | ||
| pytest | ||
| setuptools>=28.8.0 | ||
| websocket-client | ||
| websocket-client | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pandas is 3.5+