Skip to content

Fix base dependencies - #1185

Merged
bact merged 4 commits into
PyThaiNLP:devfrom
what-in-the-nim:fix-base-dependencies
Jan 10, 2026
Merged

Fix base dependencies#1185
bact merged 4 commits into
PyThaiNLP:devfrom
what-in-the-nim:fix-base-dependencies

Conversation

@what-in-the-nim

Copy link
Copy Markdown
Contributor

What does this changes

Remove pandas, numpy and pyyaml from base dependencies

What was wrong

As described in issue #1184

How this fixes it

After investigating, these three libraries are used in two modules, benchmark and misspell. In misspell, we can totally remove numpy out since we can achieve the same functionality by use built-in python module math and random (might be quicker too, since we remove numpy overhead). In benchmark, 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 install pythainlp[benchmarks] if they want to use the thainlp benchmark

Fixes

  • Remove base dependencies
  • Make misspell module, use built-in python library instead of numpy
  • Make benchmark module lazy import and warning to install extra dependency.

Your checklist for this pull request

  • Passed code styles and structures
  • Passed code linting checks and unit test

Copilot AI review requested due to automatic review settings January 10, 2026 05:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pythainlp/cli/benchmark.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots

See analysis details on SonarQube Cloud

@what-in-the-nim

what-in-the-nim commented Jan 10, 2026

Copy link
Copy Markdown
Contributor Author

SonarQube and Codacy errors on pseudo random generator (random.choice etc.)

Since this is not a security-sensitive context, we should be fine here.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 52.644% (-0.3%) from 52.947%
when pulling 33ba93b on what-in-the-nim:fix-base-dependencies
into 8819cfe on PyThaiNLP:dev.

@bact bact left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

Yes, numpy just for the floor and random are too overkill.

@bact bact added refactoring a technical improvement which does not add any new features or change existing features. dependencies Pull requests that update a dependency file benchmark benchmarking tools in the libarary labels Jan 10, 2026

@wannaphong wannaphong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@bact
bact merged commit 2d1466a into PyThaiNLP:dev Jan 10, 2026
25 of 28 checks passed
@bact bact linked an issue Jan 10, 2026 that may be closed by this pull request
@bact bact added this to the 5.3 milestone Jan 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmark benchmarking tools in the libarary dependencies Pull requests that update a dependency file refactoring a technical improvement which does not add any new features or change existing features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unnecessary base dependencies?

5 participants