Fix base dependencies - #1185
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes pandas, numpy, and PyYAML from the base dependencies of PyThaiNLP to make the package more lightweight. These libraries are now only required when using specific features like benchmarking.
Changes:
- Removed pandas, numpy, and PyYAML from base requirements in setup.py
- Refactored misspell module to use built-in Python math and random instead of numpy
- Added lazy imports with error handling to the benchmark CLI module
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| setup.py | Removed PYYAML, PANDAS, and NUMPY from base requirements list |
| pythainlp/tools/misspell.py | Replaced numpy functions with Python built-ins (math.floor, random.sample, random.choice) |
| pythainlp/cli/benchmark.py | Added lazy imports for yaml and word_tokenization with helpful error message |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Contributor
Author
|
SonarQube and Codacy errors on pseudo random generator ( Since this is not a security-sensitive context, we should be fine here. |
bact
approved these changes
Jan 10, 2026
bact
left a comment
Member
There was a problem hiding this comment.
LGTM. Thank you.
Yes, numpy just for the floor and random are too overkill.
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


What does this changes
Remove
pandas,numpyandpyyamlfrom base dependenciesWhat was wrong
As described in issue #1184
How this fixes it
After investigating, these three libraries are used in two modules,
benchmarkandmisspell. Inmisspell, we can totally removenumpyout since we can achieve the same functionality by use built-in python modulemathandrandom(might be quicker too, since we removenumpyoverhead). Inbenchmark, we can use lazy imports so that running help in parser does not raise import errors. The modules are only imported at execution time, which improves flexibility and avoids failures during help or argument parsing. I also added the warning that the user should installpythainlp[benchmarks]if they want to use thethainlp benchmarkFixes
misspellmodule, use built-in python library instead ofnumpybenchmarkmodule lazy import and warning to install extra dependency.Your checklist for this pull request