Repository navigation
Unify missing-value handling with types.Nullable - #10
Merged
Merged
Conversation
The J-Quants API represents missing values inconsistently across endpoints: null (price endpoints), empty strings (financial endpoints), and "-" for undetermined values (dividend endpoints), with numbers appearing as both JSON numbers and strings. types.Nullable[T] accepts all of these representations in one type, distinguishes absent from undetermined via IsUndetermined(), and implements MarshalJSON so decoded data can round-trip.
Dividend amounts and payable dates distinguish undetermined (-) from not set (empty), but both decoded to nil and the distinction was lost. Dividend now uses types.Nullable fields so callers can tell them apart via IsUndetermined(). This also fixes IsDividendRateUndecided(), which returned true for values that were merely not set, and drops RawDividend since Nullable fields unmarshal directly.
Replace the three raw-parsing dialects (Float64String,
Float64StringWithDash, and interface{} fields with per-file parse
helpers) with types.Nullable across all services, and delete the
legacy types along with unused Int64String and BoolString.
Futures/Option night and morning session fields change from
interface{} to *float64, so callers no longer need type assertions.
Their Has*Session() methods now report absent data as false instead
of treating a nil interface{} as present.
The margin-alert endpoint uses two more special values: "-" when the
previous day's figure was not published, and "*" for ratios that do
not apply to ETFs. Nullable now accepts "*" as absent (without the
undetermined flag), and the eight interface{} fields move to
types.NullableFloat64, replacing type-assertion accessors.
NullableInt64 routed quoted integers and decimal/exponent forms
through float64, which silently loses precision above 2^53
("9007199254740993" became 9007199254740992) and let out-of-range
values saturate instead of failing ("92233720368547758070" became
MaxInt64, "-9223372036854775809" became MinInt64).
Parse plain integer strings with strconv.ParseInt and evaluate
decimal/exponent forms exactly from the original text with big.Rat,
so values like "9007199254740993.0" now decode to the exact integer
and unrepresentable values return an error. Non-integral values now
error instead of silently truncating.
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.
概要
J-Quants APIの欠損値表現(null・空文字・
-・*・数値文字列)の処理を単一のジェネリック型types.Nullable[T]に統一し、旧カスタム型とinterface{}フィールドを全廃する。あわせて、配当情報で「未定(-)」と「非設定(空文字)」を区別して取得できるようにする。背景
欠損値の処理がファイルごとに3方言(
Float64String/Float64StringWithDash/interface{}+ ローカルパースヘルパー7個)に分かれており、「どの型がどの欠損表現を扱えるか」が暗黙知になっていた。PR #9 の空文字→0化けバグはこの非対称性が原因。変更内容
types.Nullable[T]の導入(破壊的変更)""(非設定)/"*"(該当なし。ETFの上場比など)/"-"(未定)/ 数値 / 数値文字列 を単一の型で受容Get() (T, bool)/Ptr() *T/Or(def T) T/IsUndetermined() boolのアクセサMarshalJSON実装により取得データの往復(キャッシュ保存など)が可能にNullableInt64は整数文字列をParseInt、小数・指数表記をbig.Ratで厳密に評価し、float64 の丸め(2^53超の精度損失・範囲外の飽和)を排除Float64String,Float64StringWithDash,StringWithDash, 未使用のInt64String,BoolString)と変換ヘルパーを削除公開APIの改善(破壊的変更)
DivRate等8フィールドとPayDateをNullable化し、「未定(-)」をIsUndetermined()で判別可能に。IsDividendRateUndecided()が非設定でも true を返していたバグを修正interface{}→*float64になり、型アサーション不要に。Has*Session()は nil を「データなし」として正しく判定interface{}フィールド8個 →types.NullableFloat64。「*」(ETFのため該当なし)を含む実データを正しく処理*float64を維持し、Nullableを公開するのは「未定」の区別が意味を持つ dividend のみ