From b051d60c99ff4481ac22c36c106e69b7530416ce Mon Sep 17 00:00:00 2001 From: what_in_the_nim Date: Sat, 10 Jan 2026 11:42:10 +0700 Subject: [PATCH 1/4] refactor: remove numpy dependency --- pythainlp/tools/misspell.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pythainlp/tools/misspell.py b/pythainlp/tools/misspell.py index c940d2929..a5fa84208 100644 --- a/pythainlp/tools/misspell.py +++ b/pythainlp/tools/misspell.py @@ -4,7 +4,8 @@ # SPDX-License-Identifier: Apache-2.0 from typing import List -import numpy as np +import math +import random THAI_CHARACTERS_WITHOUT_SHIFT = [ "ผปแอิืทมใฝ", @@ -126,10 +127,8 @@ def misspell(sentence: str, ratio: float = 0.05): # output: ภาษาไทยปรากฏครั้งแรกในกุทธศักราช 1727 """ - num_misspells = np.floor(len(sentence) * ratio).astype(int) - positions = np.random.choice( - len(sentence), size=num_misspells, replace=False - ) + num_misspells = math.floor(len(sentence) * ratio) + positions = random.sample(range(len(sentence)), k=num_misspells) # convert strings to array of characters misspelled = list(sentence) @@ -138,7 +137,7 @@ def misspell(sentence: str, ratio: float = 0.05): if potential_candidates is None: continue - candidate = np.random.choice(potential_candidates) + candidate = random.choice(potential_candidates) misspelled[pos] = candidate From 901d859d641cf6d4dd73afad218ac50cb38d86ff Mon Sep 17 00:00:00 2001 From: what_in_the_nim Date: Sat, 10 Jan 2026 11:43:11 +0700 Subject: [PATCH 2/4] refactor: make benchmarks lazy import --- pythainlp/cli/benchmark.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pythainlp/cli/benchmark.py b/pythainlp/cli/benchmark.py index b1b2cb7c4..e242a6162 100644 --- a/pythainlp/cli/benchmark.py +++ b/pythainlp/cli/benchmark.py @@ -8,10 +8,8 @@ import json import os -import yaml from pythainlp import cli -from pythainlp.benchmarks import word_tokenization from pythainlp.tools import safe_print @@ -88,6 +86,14 @@ def __init__(self, name, argv): % (args.input_file, args.test_file, len(actual)) ) + try: + import yaml + from pythainlp.benchmarks import word_tokenization + except ImportError: + raise ImportError( + "Please install the extra dependencies `benchmarks` to use the command by `pip install pythainlp[benchmarks]`" + ) + df_raw = word_tokenization.benchmark(expected, actual) columns = [ From c6c178af9606cfb1473b50da26dda02ee7b378c2 Mon Sep 17 00:00:00 2001 From: what_in_the_nim Date: Sat, 10 Jan 2026 11:53:10 +0700 Subject: [PATCH 3/4] chore: remove unnecessary base dependencies --- setup.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/setup.py b/setup.py index 86dc13857..0b3951cd1 100644 --- a/setup.py +++ b/setup.py @@ -45,9 +45,6 @@ requirements = [ "backports.zoneinfo; python_version<'3.9'", "requests>=2.31", - PYYAML, - PANDAS, - NUMPY, "tzdata; sys_platform == 'win32'", ] From 33ba93bd5de7773657ee4409446d0dabda820cc2 Mon Sep 17 00:00:00 2001 From: Chatcharin Sangbutsarakum <67754293+what-in-the-nim@users.noreply.github.com> Date: Sat, 10 Jan 2026 12:22:14 +0700 Subject: [PATCH 4/4] chore: format message as copilot suggested Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pythainlp/cli/benchmark.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythainlp/cli/benchmark.py b/pythainlp/cli/benchmark.py index e242a6162..68d59c10d 100644 --- a/pythainlp/cli/benchmark.py +++ b/pythainlp/cli/benchmark.py @@ -91,7 +91,7 @@ def __init__(self, name, argv): from pythainlp.benchmarks import word_tokenization except ImportError: raise ImportError( - "Please install the extra dependencies `benchmarks` to use the command by `pip install pythainlp[benchmarks]`" + "Please install the extra dependencies `benchmarks` to use this command by running `pip install pythainlp[benchmarks]`" ) df_raw = word_tokenization.benchmark(expected, actual)