def test_table_limit_wraparound_does_not_respect_partial(self): t = perspective.Table({'a':float, 'b':float}, limit=3) t.update([{'a':10}, {'b':1}, {'a':20}, {'a':None,'b':2}]) df = t.view().to_df() t2 = perspective.Table({'a':float, 'b':float}, limit=3) t2.update([{'a':10}, {'b':1}, {'a':20}, {'b':2}]) df2 = t2.view().to_df() assert df.to_dict() == df2.to_dict()
def get_table(): """Get a test table, made from "superstore.arrow" repeated `TABLE_SCALAR` times.""" with open(file_path, mode="rb") as file: arrow = file.read() table = perspective.Table(arrow) for _ in range(TABLE_SCALAR - 1): table.update(arrow) return table
def make_results_table(results_path): """Given a path to a folder containing Arrow files, create a Perspective Table from the first arrow and update with the rest. This allows us to coalesce results from individual subprocesses into one single Table.""" assert os.path.exists(results_path) table = None for file in os.listdir(results_path): path = Path(file) valid = path.suffix == ".arrow" and path.name != "results_combined.arrow" if valid: with open(os.path.join(results_path, file), "rb") as arrow: if table is not None: table.update(arrow.read()) logging.info("Updated results table with %s", file) else: table = perspective.Table(arrow.read()) logging.info("Created results table with %s", file) logging.info("Final results table size: %d", table.size()) return table
with open( os.path.join( HERE, "..", "..", "..", "..", "..", "node_modules", "superstore-arrow", "superstore.arrow", ), "rb", ) as arrow: TABLE = perspective.Table(arrow.read(), index="Row ID") VIEW = TABLE.view() def get_data(update_size): """Return `update_size` random rows from the dataset, with their Row IDs tweaked to be half appends and half partial updates.""" size = TABLE.size() start = random.randint(0, size - update_size - 1) end = start + update_size data = VIEW.to_dict(start_row=start, end_row=end) # Generate some random row IDs data["Row ID"] = [ random.randint(size, size + update_size) if i % 2 else data["Row ID"][i] for i in range(len(data["Row ID"]))
def post(self): query = self.request.body.decode("utf-8") narray = self._qconn(query) table = perspective.Table(narray) tbl_id = self._manager.host_table(table) self.write(tbl_id)
import asyncio import logging from datetime import datetime import perspective from client import PerspectiveWebSocketClient from results_schema import RESULTS_SCHEMA if __name__ == "__main__": """Run the client and dump its results to a Perspective Table before terminating.""" logging.basicConfig(level=logging.DEBUG) HERE = os.path.abspath(os.path.dirname(__file__)) RESULTS_TABLE = perspective.Table(RESULTS_SCHEMA) # The order of arguments as delivered through `main.py`. RESULTS_FOLDER = sys.argv[1] CLIENT_ID = sys.argv[2] TEST_TYPE = sys.argv[3] URL = sys.argv[4] def dump_and_exit(sig, frame): """Dump the client's results to an arrow in the results folder. Each client generates its own arrow, which can be collected and hosted using host_results.py""" if RESULTS_TABLE.size() > 0: dt = "{:%Y%m%dT%H%M%S}".format(datetime.now()) filename = "results_{}_{}.arrow".format(CLIENT_ID, dt) logging.critical(
IEXStaticDataSource, ) from schemas import holdings_schema, last_quote_schema, charts_schema # Construct our portfolio symbols = ["AAPL", "MSFT", "AMZN", "TSLA", "SPY", "SNAP", "ZM"] holdings = {symbol: random.randint(5, 10) for symbol in symbols} # Initialize the pyEX client - the API key is stored under `IEX_TOKEN` as # an environment variable. client = pyEX.Client(version="sandbox") # Create all the tables and views in one place TABLES = { "holdings": perspective.Table(holdings_schema, index="symbol"), "holdings_total": perspective.Table(holdings_schema), "quotes": perspective.Table(last_quote_schema), "charts": perspective.Table(charts_schema), } VIEWS = {name: TABLES[name].view() for name in TABLES.keys()} class MainHandler(tornado.web.RequestHandler): def set_default_headers(self): self.set_header("Access-Control-Allow-Origin", "*") self.set_header("Access-Control-Allow-Headers", "x-requested-with") self.set_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS") def get(self):