[Bug]: DataFrame mean() and std() fail on datetime and timedelta columns

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

メンテナーはふだん 2 日以内に返信

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

2026年12月4日 から。

  • #41948 @anishmehta24 による — オープン

評価

この issue はまだ評価されていません。

説明

P2 python
What happened?

mean() and std() on a deferred Series of datetime64 or timedelta64 values fail. pandas returns a Timestamp or a Timedelta:

import pandas as pd
import apache_beam as beam
from apache_beam.dataframe.transforms import DataframeTransform

df = pd.DataFrame({
    'wait': pd.to_timedelta([10, 20, 60], unit='s'),
    'at': pd.to_datetime(['2024-01-01', '2024-01-02', '2024-01-06']),
})

with beam.Pipeline() as p:
  _ = (
      p | beam.Create([df])
      | DataframeTransform(
          lambda df: df.wait.mean(), proxy=df.iloc[:0], yield_elements='pandas')
      | beam.Map(print))
# pandas gives Timedelta('0 days 00:00:30'), Beam raises ZeroDivisionError

df['at'].mean() raises TypeError: 'DatetimeArray' with dtype datetime64[ns] does not support reduction 'sum', and std() on either column raises TypeError: unsupported operand type(s) for ** or pow(): 'NaTType' and 'int'. Tz-aware datetimes and DataFrame.mean/std(numeric_only=False) fail the same way. Seen on 2.77.0 and on master.

DeferredSeries.mean divides sum() by count(), which can't work for datetimes and fails on the empty timedelta proxy (Timedelta(0) / 0). std goes through var, which squares the result of pandas std, a Timedelta here. pandas computes both on the values as floats in the unit of the dtype and converts the result back.

Issue Priority

Priority: 2 (default / most bugs should be filed as P2)

Issue Components
  • Component: Python SDK
主要言語
Java
スター
8.7k
フォーク
4.8k
平均マージ
3日 20時間
マージ済み PR(30日)
446

環境構築

はじめの一歩

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

apache/beam のほかの issue

apache/beam の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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