Skip to content
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

update python version #1868

Merged
merged 48 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ec7bf7f
update python version
SunsetWolf Dec 11, 2024
74b8e00
fix: Correct selector handling and add time filtering in storage.py
you-n-g Dec 11, 2024
0bf8943
fix: convert index and columns to list in repr methods
you-n-g Dec 11, 2024
f9e41a5
feat: Add Makefile for managing project prerequisites
you-n-g Dec 11, 2024
4f01195
feat: Add Cython extensions for rolling and expanding operations
you-n-g Dec 11, 2024
018c631
resolve install error
SunsetWolf Dec 11, 2024
009ee10
fix lint error
SunsetWolf Dec 12, 2024
c54721e
fix lint error
SunsetWolf Dec 12, 2024
58d1e05
fix lint error
SunsetWolf Dec 12, 2024
0e38d61
fix lint error
SunsetWolf Dec 12, 2024
b1685f8
fix lint error
SunsetWolf Dec 12, 2024
40ab983
update build package
SunsetWolf Dec 12, 2024
f0bd5d7
update makefile
SunsetWolf Dec 12, 2024
da9eb5d
update ci yaml
SunsetWolf Dec 12, 2024
d863765
fix docs build error
SunsetWolf Dec 12, 2024
d9da86b
fix ubuntu install error
SunsetWolf Dec 12, 2024
2bef082
fix docs build error
SunsetWolf Dec 12, 2024
4904f3d
fix install error
SunsetWolf Dec 12, 2024
3484fb7
fix install error
SunsetWolf Dec 12, 2024
c182dd4
fix install error
SunsetWolf Dec 12, 2024
da3a49f
fix install error
SunsetWolf Dec 12, 2024
60fcb71
fix pylint error
SunsetWolf Dec 12, 2024
5abfddf
fix pylint error
SunsetWolf Dec 12, 2024
4cf783f
fix pylint error
SunsetWolf Dec 12, 2024
2359552
fix pylint error
SunsetWolf Dec 12, 2024
602ca12
fix pylint error E1123
SunsetWolf Dec 12, 2024
9ea5bac
fix pylint error R0917
SunsetWolf Dec 12, 2024
b2cafd3
fix pytest error
SunsetWolf Dec 12, 2024
dea4c13
fix pytest error
SunsetWolf Dec 13, 2024
6ea6609
fix pytest error
SunsetWolf Dec 13, 2024
1e45aca
update code
SunsetWolf Dec 13, 2024
6848b77
update code
SunsetWolf Dec 13, 2024
067ea77
fix ci error
SunsetWolf Dec 13, 2024
a207d81
fix pylint error
SunsetWolf Dec 13, 2024
0dc0f38
fix black error
SunsetWolf Dec 13, 2024
202fc96
fix pytest error
SunsetWolf Dec 13, 2024
84d9d70
fix CI error
SunsetWolf Dec 13, 2024
89c7a0c
fix CI error
SunsetWolf Dec 13, 2024
ed5d71d
add python version to CI
SunsetWolf Dec 14, 2024
a369253
add python version to CI
SunsetWolf Dec 14, 2024
6a6ff93
add python version to CI
SunsetWolf Dec 14, 2024
27813eb
fix pylint error
SunsetWolf Dec 14, 2024
fd1ba4c
fix pytest general nn error
SunsetWolf Dec 14, 2024
561abaf
fix CI error
SunsetWolf Dec 14, 2024
825deb2
optimize code
SunsetWolf Dec 16, 2024
e67553b
add coments
SunsetWolf Dec 16, 2024
32782ed
Extended macos version
SunsetWolf Dec 16, 2024
47f50ad
remove build package
SunsetWolf Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/test_qlib_from_source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
# so we limit the macos version to macos-13.
os: [windows-latest, ubuntu-20.04, ubuntu-22.04, macos-13]
# not supporting 3.6 due to annotations is not supported https://stackoverflow.com/a/52890129
python-version: [3.7, 3.8]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- name: Test qlib from source
Expand Down Expand Up @@ -63,8 +63,7 @@ jobs:

- name: Set up Python tools
run: |
python -m pip install --upgrade cython
python -m pip install -e .[dev]
make dev
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved

- name: Lint with Black
# Python 3.7 will use a black with low level. So we use python with higher version for black check
Expand Down Expand Up @@ -108,8 +107,8 @@ jobs:
# We use sys.setrecursionlimit(2000) to make the recursion depth larger to ensure that pylint works properly (the default recursion depth is 1000).
- name: Check Qlib with pylint
run: |
pylint --disable=C0104,C0114,C0115,C0116,C0301,C0302,C0411,C0413,C1802,R0401,R0801,R0902,R0903,R0911,R0912,R0913,R0914,R0915,R1720,W0105,W0123,W0201,W0511,W0613,W1113,W1514,E0401,E1121,C0103,C0209,R0402,R1705,R1710,R1725,R1735,W0102,W0212,W0221,W0223,W0231,W0237,W0612,W0621,W0622,W0703,W1309,E1102,E1136 --const-rgx='[a-z_][a-z0-9_]{2,30}$' qlib --init-hook "import astroid; astroid.context.InferenceContext.max_inferred = 500; import sys; sys.setrecursionlimit(2000)"
pylint --disable=C0104,C0114,C0115,C0116,C0301,C0302,C0411,C0413,C1802,R0401,R0801,R0902,R0903,R0911,R0912,R0913,R0914,R0915,R1720,W0105,W0123,W0201,W0511,W0613,W1113,W1514,E0401,E1121,C0103,C0209,R0402,R1705,R1710,R1725,R1735,W0102,W0212,W0221,W0223,W0231,W0237,W0246,W0612,W0621,W0622,W0703,W1309,E1102,E1136 --const-rgx='[a-z_][a-z0-9_]{2,30}$' scripts --init-hook "import astroid; astroid.context.InferenceContext.max_inferred = 500; import sys; sys.setrecursionlimit(2000)"
pylint --disable=C0104,C0114,C0115,C0116,C0301,C0302,C0411,C0413,C1802,R0401,R0801,R0902,R0903,R0911,R0912,R0913,R0914,R0915,R0917,R1720,W0105,W0123,W0201,W0511,W0613,W1113,W4904,W1514,E0401,E1121,C0103,C0209,R0402,R1705,R1710,R1725,R1735,W0102,W0212,W0221,W0223,W0231,W0237,W0612,W0621,W0622,W0703,W1309,E1102,E1136 --const-rgx='[a-z_][a-z0-9_]{2,30}$' qlib --init-hook "import astroid; astroid.context.InferenceContext.max_inferred = 500; import sys; sys.setrecursionlimit(2000)"
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved
pylint --disable=C0104,C0114,C0115,C0116,C0301,C0302,C0411,C0413,C1802,R0401,R0801,R0902,R0903,R0911,R0912,R0913,R0914,R0915,R0917,R1720,W0105,W0123,W0201,W0511,W0613,W1113,W1514,E0401,E1121,E1123,C0103,C0209,R0402,R1705,R1710,R1725,R1735,W0102,W0212,W0221,W0223,W0231,W0237,W0246,W0612,W0621,W0622,W0703,W1309,E1102,E1136 --const-rgx='[a-z_][a-z0-9_]{2,30}$' scripts --init-hook "import astroid; astroid.context.InferenceContext.max_inferred = 500; import sys; sys.setrecursionlimit(2000)"

# The following flake8 error codes were ignored:
# E501 line too long
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/test_qlib_from_source_slow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
# so we limit the macos version to macos-13.
os: [windows-latest, ubuntu-20.04, ubuntu-22.04, macos-13]
# not supporting 3.6 due to annotations is not supported https://stackoverflow.com/a/52890129
python-version: [3.7, 3.8]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- name: Test qlib from source slow
Expand All @@ -44,9 +44,7 @@ jobs:

- name: Set up Python tools
run: |
python -m pip install --upgrade pip
pip install --upgrade cython numpy
pip install -e .[dev]
make dev

- name: Downloads dependencies data
run: |
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ tags
*.swp

./pretrain
.idea/
.idea/
.aider*
7 changes: 6 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
include qlib/VERSION.txt
exclude tests/*
include qlib/*
include qlib/*/*
include qlib/*/*/*
include qlib/*/*/*/*
include qlib/*/*/*/*/*
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved
147 changes: 147 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
.PHONY: prerequisite clean deepclean install init-qlib-env dev constraints black isort mypy ruff toml-sort lint pre-commit test-run test build upload docs-autobuild changelog docs-gen docs-mypy docs-coverage docs
#You can modify it according to your terminal
SHELL := /bin/bash

########################################################################################
# Variables
########################################################################################

# Documentation target directory, will be adapted to specific folder for readthedocs.
PUBLIC_DIR := $(shell [ "$$READTHEDOCS" = "True" ] && echo "$$READTHEDOCS_OUTPUT/html" || echo "public")

SO_DIR := qlib/data/_libs
SO_FILES := $(wildcard $(SO_DIR)/*.so)

########################################################################################
# Development Environment Management
########################################################################################
# Remove common intermediate files.
clean:
-rm -rf \
$(PUBLIC_DIR) \
qlib/data/_libs/*.cpp \
qlib/data/_libs/*.so \
mlruns \
public \
build \
.coverage \
.mypy_cache \
.pytest_cache \
.ruff_cache \
Pipfile* \
coverage.xml \
dist \
release-notes.md

find . -name '*.egg-info' -print0 | xargs -0 rm -rf
find . -name '*.pyc' -print0 | xargs -0 rm -f
find . -name '*.swp' -print0 | xargs -0 rm -f
find . -name '.DS_Store' -print0 | xargs -0 rm -f
find . -name '__pycache__' -print0 | xargs -0 rm -rf

# Remove pre-commit hook, virtual environment alongside itermediate files.
deepclean: clean
if command -v pre-commit > /dev/null 2>&1; then pre-commit uninstall --hook-type pre-push; fi
if command -v pipenv >/dev/null 2>&1 && pipenv --venv >/dev/null 2>&1; then pipenv --rm; fi

# Prerequisite section
# What this code does is compile two Cython modules, rolling and expanding, using setuptools and Cython,
# and builds them as binary expansion modules that can be imported directly into Python.
# Since pyproject.toml can't do that, we compile it here.
prerequisite:
@if [ -n "$(SO_FILES)" ]; then \
echo "Shared library files exist, skipping build."; \
else \
echo "No shared library files found, building..."; \
pip install --upgrade setuptools wheel; \
python -m pip install cython; \
python -m pip install "numpy<2.0.0"; \
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved
python -c "from setuptools import setup, Extension; from Cython.Build import cythonize; import numpy; extensions = [Extension('qlib.data._libs.rolling', ['qlib/data/_libs/rolling.pyx'], language='c++', include_dirs=[numpy.get_include()]), Extension('qlib.data._libs.expanding', ['qlib/data/_libs/expanding.pyx'], language='c++', include_dirs=[numpy.get_include()])]; setup(ext_modules=cythonize(extensions, language_level='3'), script_args=['build_ext', '--inplace'])"; \
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved
fi

# Install the package in editable mode.
dependencies:
python -m pip install -e .

lightgbm:
python -m pip install lightgbm --prefer-binary

rl:
python -m pip install -e .[rl]

develop:
python -m pip install -e .[dev]

lint:
python -m pip install -e .[lint]

docs:
python -m pip install -e .[docs]

package:
python -m pip install -e .[package]

test:
python -m pip install -e .[test]

analysis:
python -m pip install -e .[analysis]

all:
python -m pip install -e .[rl,dev,lint,docs,package,test,analysis]

install: prerequisite dependencies

dev: prerequisite all

########################################################################################
# Lint and pre-commit
########################################################################################

# Check lint with black.
black:
black . -l 120 --check --diff

# Check code folder with pylint.
pylint:
pylint --disable=C0104,C0114,C0115,C0116,C0301,C0302,C0411,C0413,C1802,R0401,R0801,R0902,R0903,R0911,R0912,R0913,R0914,R0915,R0917,R1720,W0105,W0123,W0201,W0511,W0613,W1113,W1514,W4904,E0401,E1121,C0103,C0209,R0402,R1705,R1710,R1725,R1730,R1735,W0102,W0212,W0221,W0223,W0231,W0237,W0612,W0621,W0622,W0703,W1309,E1102,E1136 --const-rgx='[a-z_][a-z0-9_]{2,30}' qlib --init-hook="import astroid; astroid.context.InferenceContext.max_inferred = 500; import sys; sys.setrecursionlimit(2000)"
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved
pylint --disable=C0104,C0114,C0115,C0116,C0301,C0302,C0411,C0413,C1802,R0401,R0801,R0902,R0903,R0911,R0912,R0913,R0914,R0915,R0917,R1720,W0105,W0123,W0201,W0511,W0613,W1113,W1514,E0401,E1121,E1123,C0103,C0209,R0402,R1705,R1710,R1725,R1735,W0102,W0212,W0221,W0223,W0231,W0237,W0246,W0612,W0621,W0622,W0703,W1309,E1102,E1136 --const-rgx='[a-z_][a-z0-9_]{2,30}' scripts --init-hook="import astroid; astroid.context.InferenceContext.max_inferred = 500; import sys; sys.setrecursionlimit(2000)"

# Check code with flake8.
flake8:
flake8 --ignore=E501,F541,E266,E402,W503,E731,E203 --per-file-ignores="__init__.py:F401,F403" qlib

# Check code with mypy.
mypy:
mypy qlib --install-types --non-interactive
mypy qlib --verbose

# Check ipynb with nbqa.
nbqa:
nbqa black . -l 120 --check --diff
nbqa pylint . --disable=C0104,C0114,C0115,C0116,C0301,C0302,C0411,C0413,C1802,R0401,R0801,R0902,R0903,R0911,R0912,R0913,R0914,R0915,R1720,W0105,W0123,W0201,W0511,W0613,W1113,W1514,E0401,E1121,C0103,C0209,R0402,R1705,R1710,R1725,R1735,W0102,W0212,W0221,W0223,W0231,W0237,W0612,W0621,W0622,W0703,W1309,E1102,E1136,W0719,W0104,W0404,C0412,W0611,C0410 --const-rgx='[a-z_][a-z0-9_]{2,30}'

# Check ipynb with nbconvert.
nbconvert:
jupyter nbconvert --to notebook --execute examples/workflow_by_code.ipynb

lint: black pylint flake8 mypy nbqa

########################################################################################
# Package
########################################################################################

# Build the package.
build:
python -m build

# Upload the package.
upload:
python -m twine upload dist/*

########################################################################################
# Documentation
########################################################################################

docs-gen:
python -m sphinx.cmd.build -W docs $(PUBLIC_DIR)
5 changes: 3 additions & 2 deletions examples/benchmarks/TRA/example.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import argparse

import qlib
import ruamel.yaml as yaml
from ruamel.yaml import YAML
from qlib.utils import init_instance_by_config


def main(seed, config_file="configs/config_alstm.yaml"):
# set random seed
with open(config_file) as f:
config = yaml.safe_load(f)
yaml = YAML(typ="safe", pure=True)
config = yaml.load(f)

# seed_suffix = "/seed1000" if "init" in config_file else f"/seed{seed}"
seed_suffix = ""
Expand Down
5 changes: 3 additions & 2 deletions examples/data_demo/data_cache_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from pathlib import Path
import pickle
from pprint import pprint
from ruamel.yaml import YAML
import subprocess
import yaml
from qlib.log import TimeInspector

from qlib import init
Expand All @@ -30,7 +30,8 @@
subprocess.run(f"qrun {config_path}", shell=True)

# 2) dump handler
task_config = yaml.safe_load(config_path.open())
yaml = YAML(typ="safe", pure=True)
task_config = yaml.load(config_path.open())
hd_conf = task_config["task"]["dataset"]["kwargs"]["handler"]
pprint(hd_conf)
hd: DataHandlerLP = init_instance_by_config(hd_conf)
Expand Down
6 changes: 3 additions & 3 deletions examples/data_demo/data_mem_resuse_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
from pathlib import Path
import pickle
from pprint import pprint
from ruamel.yaml import YAML
import subprocess

import yaml

from qlib import init
from qlib.data.dataset.handler import DataHandlerLP
from qlib.log import TimeInspector
Expand All @@ -29,7 +28,8 @@
exp_name = "data_mem_reuse_demo"

config_path = DIRNAME.parent / "benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml"
task_config = yaml.safe_load(config_path.open())
yaml = YAML(typ="safe", pure=True)
task_config = yaml.load(config_path.open())

# 1) without using processed data in memory
with TimeInspector.logt("The original time without reusing processed data in memory:"):
Expand Down
5 changes: 3 additions & 2 deletions examples/run_all_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import fire
import time
import glob
import yaml
import shutil
import signal
import inspect
Expand All @@ -15,6 +14,7 @@
import statistics
import subprocess
from datetime import datetime
from ruamel.yaml import YAML
from pathlib import Path
from operator import xor
from pprint import pprint
Expand Down Expand Up @@ -188,7 +188,8 @@ def gen_and_save_md_table(metrics, dataset):
# read yaml, remove seed kwargs of model, and then save file in the temp_dir
def gen_yaml_file_without_seed_kwargs(yaml_path, temp_dir):
with open(yaml_path, "r") as fp:
config = yaml.safe_load(fp)
yaml = YAML(typ="safe", pure=True)
config = yaml.load(fp)
try:
del config["task"]["model"]["kwargs"]["seed"]
except KeyError:
Expand Down
88 changes: 87 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,88 @@
[build-system]
requires = ["setuptools", "numpy", "Cython"]
requires = ["setuptools", "cython", "numpy<2.0.0"]
build-backend = "setuptools.build_meta"

[project]
classifiers = [
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
"License :: OSI Approved :: MIT License",
"Development Status :: 3 - Alpha",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
name = "pyqlib"
dynamic = ["version"]
description = "A Quantitative-research Platform"
requires-python = ">=3.8.0"

dependencies = [
"pyyaml",
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved
"numpy",
"pandas",
"mlflow>=2.0.0",
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved
"filelock",
"redis",
"dill",
"fire",
"ruamel.yaml>=0.17.38",
"python-redis-lock",
"tqdm",
"pymongo",
"loguru",
"lightgbm",
"gym",
"cvxpy",
"joblib",
"matplotlib",
"jupyter",
"nbconvert",
]

[project.optional-dependencies]
dev = [
"pytest",
"statsmodels",
]
rl = [
"tianshou<=0.4.10",
"torch",
]
lint = [
"black",
"pylint",
"mypy<1.5.0",
"flake8",
"nbqa",
]
docs = [
"sphinx",
"sphinx_rtd_theme",
"readthedocs_sphinx_ext",
]
package = [
"twine",
"build",
]
# test_pit dependency packages
test = [
"yahooquery",
"baostock",
]
analysis = [
"plotly",
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved
]

[tool.setuptools]
packages = [
"qlib",
]

[project.scripts]
qrun = "qlib.workflow.cli:run"
Loading
Loading