Skip to main content

Some Python tools

Project description

pyttkl

Links

Description

Some Python tools

kits.py

  • This module contains utility functions for handling strings, lists, and other data types.
  • Extensions related to logging
  • Extensions related to argparse

tmat.py

  • A Trivial Matrix concept implementation that can read and write pd.DataFrame.
  • Although internally it is stored as numpy-compatible data, considering pd.DataFrame(ndarray), it essentially wraps an ndarray or adds row and column names.
  • load_tmat(filename, mmap_mode='c'): Automatically determines the payload type based on the meta information in the file and reads it. If the payload is mmap, you can specify mmap_mode.
  • save_tmat(filename, tmat, compress='zstd'): Allows compressing the payload with zstd. There are more options in the code. It can also save as mmap.

Installation

You can install this package using pip:

pip install .

Design

tmat format:

  • Design Goals:
      1. Compatible with numpy's ndarray
      1. Compatible with pandas' DataFrame
      1. Supports compression
      1. Supports mmap
      1. Supports multiple data types
      1. Native support for both C++ and Python
      1. Understandable by quantitative researchers by reading the code
  • Example: TMT\n{header_length: 954}\n{"columns": ["a", "b", "c"], "rows": [1, 2, 3], "dtype": "int32", "compress": "zstd"}\n{payload}
  • Header: 4-byte magic number, TMT\n
  • JSON string {"header_length": 954}\n. If header_length > 0, the following meta is a payload compressed with lz4 of length header_length. Otherwise, it is a plain JSON string.
    • Trick: Use head -2 KLINE/OPEN/202401.tmt to view the file header.
  • Meta: JSON string {"columns": ["a", "b", "c"], "rows": [1, 2, 3], "dtype": "int32", "compress": "zstd"}\n
  • Payload: Binary data. The specific format depends on the meta content.
    • If {"compress": "zstd"}, it is zstd-compressed binary data. It can also be lz4 or zstd.
    • Otherwise, it is plain binary data, which can be directly loaded with mmap. You can specify the loading mode with mmap_mode.
      • Trick: You can use pandas and numpy's inplace operations to modify the file content directly. Be sure to check ndarray.flags when using it.

TODOS or NO-TODOS

There are many things that can be done, but to keep the project simple and at a level understandable by quantitative researchers, many TODOs become NO TODOs. Of course, if anyone thinks something can be improved, feel free to create an issue.

  • TODOs

    • Code comments
    • Code documentation
    • Restrict exposed APIs
  • NO TODOs

    • Multithreading

Requirements

  • Python 3.11 or higher

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyttkl-0.1.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyttkl-0.1.0-py3-none-any.whl (2.5 kB view details)

Uploaded Python 3

File details

Details for the file pyttkl-0.1.0.tar.gz.

File metadata

  • Download URL: pyttkl-0.1.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for pyttkl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 27f9b65d04477a571cce60acb7e7af796649df3b928cfb30850aa3155c9c5641
MD5 fda5fb7ccd34187a7c19b30b8e086c92
BLAKE2b-256 675527c9b05a09bfb6340b60c8d3c565a89ce36d93ef76a2f8d5bb48c597b1d3

See more details on using hashes here.

File details

Details for the file pyttkl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyttkl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for pyttkl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bfaf3dc1988b37e6900fb712245d7d9efca071e7e41cf1ce0d99fb39f7075f4
MD5 0ba8c6d0bead7bcc2f161e6f83a007e3
BLAKE2b-256 11a1af0f691489199f34365da65a204e5c3f4e01d874730801a632b398a880ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page