Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

cc() truncates periodic coordinates for integer input with fractional bounds

オープン
#272 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@ktz03 がすでに取り組んでいます。

2026年10月12日 から。

  • #273 @ktz03 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
numpy, python
領域
data

調査の方向性

Start with _map_cyclic() in the cyclic spline implementation and trace how it handles integer coordinates with fractional bounds; compare that path with the natural spline cr() control described in the issue. Reproduce the provided direct cc() and DesignInfo prediction examples with integer and float inputs, then verify both produce matching bases while preserving input immutability.

索引モデルが issue の本文から書いたものです。

説明

cc() silently truncates periodic coordinates when its input has an integer dtype and its exterior bounds are non-integral. The same numeric values produce different spline bases when passed as integers and floats, including when predicting with an existing DesignInfo.

Reproduced with the latest PyPI release, Patsy 1.0.3, and current master 8ce7441586fc228b9ff487a97e3a6ebe9fde6aad on Windows with Python 3.13.15, NumPy 2.5.4 and SciPy 1.18.1:

import numpy as np
from patsy import cc, dmatrix, build_design_matrices

x = np.arange(-1, 6)
kwargs = dict(knots=[1., 2., 3.], lower_bound=0.1, upper_bound=3.4)
integer_basis = cc(x, **kwargs)
float_basis = cc(x.astype(float), **kwargs)
print(np.max(np.abs(integer_basis - float_basis)))
# 1.1751149047931713 (expected: 0)

formula = "0 + cc(x, knots=[1., 2., 3.], lower_bound=0.1, upper_bound=3.4)"
training = dmatrix(formula, {"x": np.array([1., 2., 3.])})
integer_prediction = build_design_matrices([training.design_info], {"x": x})[0]
float_prediction = build_design_matrices([training.design_info], {"x": x.astype(float)})[0]
print(np.max(np.abs(integer_prediction - float_prediction)))
# 1.1751149047931713 (expected: 0)

For example, the period is 3.3, so x=4 maps to approximately 0.7. _map_cyclic() writes that coordinate into a copy of the integer input and truncates it to zero; its subsequent lower-bound mapping then moves it to another incorrect coordinate. The returned design matrix contains no warning about this loss of precision.

Integer and float input agree for points inside the bounds, for whole-number exterior bounds, and for the corresponding natural spline cr() control. A fix can convert integer coordinates to floating point before periodic mapping while preserving the existing floating-point input dtype and input immutability.

主要言語
Python
スター
989
フォーク
108
平均マージ
1日 1時間
マージ済み PR(30日)
3

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pydata/patsy のほかの issue

pydata/patsy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。