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

Đang mở
#41,947 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@anishmehta24 đang làm issue này rồi.

Từ ngày 4/12/2026.

  • #41948 của @anishmehta24 — đang mở

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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
Ngôn ngữ chính
Java
Star
8.7k
Fork
4.8k
Merge trung bình
3 ngày 20 giờ
Pull request đã merge (30 ngày)
446

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/beam

Tất cả issue của apache/beam

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.