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.1.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.1-py3-none-any.whl (2.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyttkl-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 74dce03376ae06745c8104726209796208ae03777ddc14c89e940a93dbf80e54
MD5 c3896133f02b0b3e6627cf7cd372c9f9
BLAKE2b-256 06934ce1f589a46df0e2dd165abe3ac4a12228964990eaee4c36cbff8bd8eee6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyttkl-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 26d60093862f4217bfbf82749d28f0f05467e89ea3cf72b3541dc5f9748b6c99
MD5 b8b797e7bff5e032003caa2792fdb962
BLAKE2b-256 658292e0fea45bce60437c429c99c46673f24f33df006c9e42d0f1b484c9acbb

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