Utilities for parsing Japanese numeric ranges.
Project description
jp-range
jp-range is a small library for parsing Japanese numeric range expressions. It returns an Interval object implemented with Pydantic or None when parsing fails.
Installation
pip install jp-range
# or install from GitHub
pip install git+https://github.com/first-automation/jp-range.git
Python 3.12 or later is required.
Features
- Normalizes full width numbers and common punctuation
- Supports inclusive and exclusive bounds (
以上,未満, etc.) - Parses connectors such as
〜,-andから - Handles single-sided bounds, approximate expressions (
90前後) andA±dnotation - Integrates with pandas via
apply_parseforSeriesandDataFrame
Usage
Basic parsing
from jp_range import parse
interval = parse("40以上50未満")
print(interval) # [40, 50)
print(interval.contains(45)) # True
Pandas integration
from pandas import Series
from jp_range import apply_parse
# Convert Series of textual ranges to pandas.Interval
s = Series(["20~30", "50超", "未満100"])
result = apply_parse(s)
# result:
# 0 [20.0, 30.0]
# 1 (50.0, inf)
# 2 (-inf, 100.0)
# dtype: object
# Expand columns into numeric min/max
df = apply_parse(s.to_frame(name="range"), split_numeric=True)
# df:
# range_max range_min
# 0 30.0 20.0
# 1 NaN 50.0
# 2 100.0 NaN
Supported expressions
"20から30"– inclusive 20 to 30"20〜30"– inclusive 20 to 30 using a tilde connector"30以上40以下"– inclusive 30 to 40"40以上50未満"– 40 to under 50"70超90以下"– greater than 70 and up to 90"50より上"– greater than 50"60より下"– less than 60"90前後"– roughly around 90 (5% margin)"(2,3]"– standard interval notation
parse_jp_range returns None if the expression cannot be parsed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jp_range-0.4.0.tar.gz.
File metadata
- Download URL: jp_range-0.4.0.tar.gz
- Upload date:
- Size: 21.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34afe51686616e26787a6164e59264ef64e71373ce6ea20c9aa22b5d17e6b864
|
|
| MD5 |
ee9650bcb8dd0de458de4c1fe46fe107
|
|
| BLAKE2b-256 |
d2a34f9fb7684e0ce5862521009765e9630a36ec7d779143692aae6142e9d8f0
|
File details
Details for the file jp_range-0.4.0-py3-none-any.whl.
File metadata
- Download URL: jp_range-0.4.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
396ce47dea00e7b22d535c78a4faa2893547a690c9ebd2e47cb8937009b6c7a3
|
|
| MD5 |
ca9bed511978240812720e56951abbff
|
|
| BLAKE2b-256 |
faf9ad98ace6748e0e9419cda96b029bbe17ddaeefce6f0953ba943ffd0a97c4
|