Skip to content

Add solutions for Product Price at a Given Date (1164) in PostgreSQL …#270

Merged
myoshi2891 merged 2 commits into
mainfrom
dev-from-macmini
Feb 15, 2026
Merged

Add solutions for Product Price at a Given Date (1164) in PostgreSQL …#270
myoshi2891 merged 2 commits into
mainfrom
dev-from-macmini

Conversation

@myoshi2891

Copy link
Copy Markdown
Owner

…and Pandas

Product Price at a Given Date/
Product_Price_at_a_Given_Date.html (新規追加)
Product_Price_at_a_Given_Date_pandas.md (新規追加)
Product_Price_at_a_Given_Date_postgreSQL.md (新規追加)

@coderabbitai

coderabbitai Bot commented Feb 15, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Summary by CodeRabbit

リリースノート

  • Documentation
    • Pandas を使った「Product Price at a Given Date」解法ドキュメントを追加(手順、複数例、実行例、フローチャート、挙動説明を含む)
    • PostgreSQL 16.6+ 向けの同問題ドキュメントを追加(DISTINCT ON、ウィンドウ関数、スカラーサブクエリ等の実装例と解説)
  • New Features
    • Pandas 実行サンプルの Python コード例を同梱

Walkthrough

LeetCode 1164「Product Price at a Given Date」向けに、Pandasベースの実装ファイルとPostgreSQL向け解法ドキュメントを追加。Pandas実装は指定日付時点の最新価格算出と欠損時のデフォルト補填を示す。

Changes

Cohort / File(s) Summary
Pandas実装 & 実行例
SQL/Leetcode/Intermediate Join/1164. Product Price at a Given Date/Claude Sonnet 4.5 Extended/Product_Price_at_a_Given_Date_pandas.md, SQL/Leetcode/Intermediate Join/1164. Product Price at a Given Date/Claude Sonnet 4.5 Extended/price_solution.py
新規ドキュメントとPython実装を追加。price_at_given_date(products: pd.DataFrame) -> pd.DataFrame を実装し、change_date <= 2019-08-16でフィルタ、groupby(...).idxmax()で最新行取得、全product_idにマップして未存在は価格10で補填する流れを記載。出力はproduct_id, price(int)。
PostgreSQL 解法ドキュメント
SQL/Leetcode/Intermediate Join/1164. Product Price at a Given Date/Claude Sonnet 4.5 Extended/Product_Price_at_a_Given_Date_postgreSQL.md
PostgreSQL向けにDISTINCT ONを用いる単一クエリ案、ウィンドウ関数(ROW_NUMBER)版、スカラ副問い合わせ版を説明。COALESCEでデフォルト10を扱う方法、複数ケースの例と計算量注記、Mermaid図を追加。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 日付を辿りし私の足で
最新の値をそっと探すよ
パンダとSQLを抱えつつ
足りぬ価格には十を添えて
小さなジャンプで解を祝う

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding solutions for LeetCode problem 1164 in PostgreSQL and Pandas. It is concise and specific about what was added.
Description check ✅ Passed The description is related to the changeset, listing the specific files added (HTML, Pandas markdown, PostgreSQL markdown) for the Product Price at a Given Date problem.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@SQL/Leetcode/Intermediate` Join/1164. Product Price at a Given Date/Claude
Sonnet 4.5 Extended/Product_Price_at_a_Given_Date_pandas.md:
- Around line 161-305: Remove the duplicated documentation block that repeats
the entire explanation and the price_at_given_date implementation (the repeated
sections starting with the heading "## ⭐ 0) 前提" and including the code sample,
algorithm/flow, complexity table, diagram and execution example). Keep the
first/original occurrence of those sections and delete the second copy so the
file contains only the single canonical description and implementation of
price_at_given_date.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@SQL/Leetcode/Intermediate` Join/1164. Product Price at a Given Date/Claude
Sonnet 4.5 Extended/Product_Price_at_a_Given_Date_pandas.md:
- Line 7: The execution examples include print(result) which conflicts with the
"print禁止" requirement; either remove all print(...) calls from the examples
(including the occurrence shown as print(result) and the similar prints around
the later examples) or explicitly mark those prints as "ローカル検証用" so the examples
and requirements are consistent; update the example text accordingly and ensure
no remaining print(...) calls appear in the published examples.
- Around line 43-46: The comparison against target_date is unsafe if
products['change_date'] is not normalized to datetime; convert
products['change_date'] using pd.to_datetime (e.g., products['change_date'] =
pd.to_datetime(products['change_date'])) and make target_date a pandas Timestamp
(e.g., target_date = pd.Timestamp('2019-08-16')) before computing before_target
= products[products['change_date'] <= target_date] so both sides share the same
datetime dtype and comparisons are stable.


- 環境: **Python 3.10.15 / pandas 2.2.2**
- 指定シグネチャ厳守
- IO禁止、print禁止、不要sort禁止

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.

⚠️ Potential issue | 🟡 Minor

「print禁止」と実行例の整合性が崩れています

要件で print禁止 とある一方、実行例で print(result) を使っています。読者が迷うので、実行例から print を外すか「ローカル検証用」と明記してください。

Also applies to: 138-140

🤖 Prompt for AI Agents
In `@SQL/Leetcode/Intermediate` Join/1164. Product Price at a Given Date/Claude
Sonnet 4.5 Extended/Product_Price_at_a_Given_Date_pandas.md at line 7, The
execution examples include print(result) which conflicts with the "print禁止"
requirement; either remove all print(...) calls from the examples (including the
occurrence shown as print(result) and the similar prints around the later
examples) or explicitly mark those prints as "ローカル検証用" so the examples and
requirements are consistent; update the example text accordingly and ensure no
remaining print(...) calls appear in the published examples.

Comment on lines +43 to +46
# --- 対象日以前のデータのみ抽出
target_date = '2019-08-16'
before_target = products[products['change_date'] <= target_date]

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.

🧹 Nitpick | 🔵 Trivial

日時型の正規化を明示してください(比較の型ぶれ回避)

change_date のdtypeが datetime64 / object で揺れると比較が不安定になる可能性があります。pd.Timestamppd.to_datetime で明示的に揃える方が安全です。

♻️ 修正案(例)
-    target_date = '2019-08-16'
-    before_target = products[products['change_date'] <= target_date]
+    target_date = pd.Timestamp('2019-08-16')
+    change_date = pd.to_datetime(products['change_date'], errors='coerce')
+    before_target = products[change_date <= target_date]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# --- 対象日以前のデータのみ抽出
target_date = '2019-08-16'
before_target = products[products['change_date'] <= target_date]
# --- 対象日以前のデータのみ抽出
target_date = pd.Timestamp('2019-08-16')
change_date = pd.to_datetime(products['change_date'], errors='coerce')
before_target = products[change_date <= target_date]
🤖 Prompt for AI Agents
In `@SQL/Leetcode/Intermediate` Join/1164. Product Price at a Given Date/Claude
Sonnet 4.5 Extended/Product_Price_at_a_Given_Date_pandas.md around lines 43 -
46, The comparison against target_date is unsafe if products['change_date'] is
not normalized to datetime; convert products['change_date'] using pd.to_datetime
(e.g., products['change_date'] = pd.to_datetime(products['change_date'])) and
make target_date a pandas Timestamp (e.g., target_date =
pd.Timestamp('2019-08-16')) before computing before_target =
products[products['change_date'] <= target_date] so both sides share the same
datetime dtype and comparisons are stable.

@myoshi2891 myoshi2891 merged commit be505ee into main Feb 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant