Skip to content
All findings

Upgrading a pandas ETL from 2.2 to 3.1: only 'Invalid frequency: H' crashes, and 4 results change silently

Published 30 Nov 2026

On pandas 3.1.1 a small orders ETL written for pandas 2.2.3 crashed once (resample('H')). After that fix it ran to completion with wrong data: epoch timestamps 1000x too small (datetime64[us] instead of [ns]), fillna(inplace=True) and df[col][mask] = v doing nothing under Copy-on-Write, and dtype == object returning False for the new str dtype. Exact outputs and fixes that work on both 2.2 and 3.x.

When I moved a small CSV→warehouse ETL from pandas 2.2.3 to 3.1.1, the only crash was ValueError: Invalid frequency: H. Once that was fixed, the script ran cleanly but produced wrong data in four places: epoch seconds 1000x too small, refunds not clamped, missing regions not filled, and a "is this column text" check returning False. The fixes are "h", .loc[...] / reassignment instead of chained writes, unit-safe epoch math, and is_string_dtype. All of them also work on pandas 2.2.

log
ValueError: Invalid frequency: H. Failed to parse with error message: ValueError('Invalid frequency: H. Did you mean h?') Did you mean h?

Environment: Docker python:3.12-slim (Python 3.12.16). pandas 2.2.3 → 3.1.1, numpy 2.5.5 in both. Reproduced 2026-11-30.

The project: etl.py reads orders.csv with parse_dates, upper-cases the text columns, fills missing region/discount, clamps negative amounts to 0, adds created_epoch (seconds), and prints hourly revenue. Baseline output on 2.2.3 is in repro/step0-baseline-pandas2.2.3.log.

1. pandas 3: ValueError: Invalid frequency: H

resample("H") (also "T", "S", "L", etc.) was deprecated in 2.2 and now raises. Use lowercase: resample("h"). This was the only crash.

2. pandas 3: astype("int64") on datetimes is 1000x smaller (datetime64[us], not [ns])

After fixing "H", the output had created_epoch = 1767604 instead of 1767604500. No error and no warning. In pandas 3.x, read_csv(parse_dates=...) returns datetime64[us], not datetime64[ns] (repro/dtypes-compare.log):

log
pandas 2.2.3  created_at datetime64[ns]  int64 of first ts: 1767604500000000000pandas 3.1.1  created_at datetime64[us]  int64 of first ts: 1767604500000000

So astype("int64") // 10**9 now divides microseconds by 10^9. Fix, independent of the unit:

python
df["created_epoch"] = (df["created_at"] - pd.Timestamp("1970-01-01")) // pd.Timedelta("1s")

3. pandas 3: df[col][mask] = value silently does nothing (Copy-on-Write)

df["amount"][df["amount"] < 0] = 0 left -15.0 in place, and hourly revenue for 13:00 became 45.0 instead of 60.0. pandas 3.x only emits a warning:

log
ChainedAssignmentError: A value is being set on a copy of a DataFrame or Series through chained assignment.

Fix: df.loc[df["amount"] < 0, "amount"] = 0.

4. pandas 3: df[col].fillna(..., inplace=True) silently does nothing

df["region"].fillna("UNKNOWN", inplace=True) left NaN in the output. Same Copy-on-Write cause and the same kind of warning. Fix: df["region"] = df["region"].fillna("UNKNOWN"). Copy-on-Write makes this kind of inplace=True on a column a no-op.

5. pandas 3: dtype == object is False for text columns (new str dtype)

Text columns are now str (StringDtype), so df["customer"].dtype == object printed customer is text: False and the loader would treat it as non-text. Fix: pd.api.types.is_string_dtype(df["customer"]). select_dtypes(include="object") still returns string columns in 3.1.1, but it emits Pandas4Warning: ... This behavior is deprecated. Use include=["object", "string"].

How to detect

Run the job once with python -W error::Warning on pandas 3. Issues 3–5 only show up as warnings, and #2 shows nothing at all. Diff the output against a 2.x run. That diff is how I found #2.

What didn't work

  • Fixing only the crash ("H" → "h"): the job then "passed" with 4 wrong columns (repro/step2-freq-h-fixed.log).
  • pd.Timedelta(seconds=1) under -W error on pandas 2.2.3 with numpy 2.5.5: it raises numpy's DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated. pd.Timedelta("1s") raises the same (repro/pandas2.2.3-numpy2.5-timedelta-warning.log). On 2.2.3, run without -W error; the result is correct.

Final working setup

pandas==3.1.1 (numpy 2.5.5). The migrated repro/app-v3/etl.py gives the same output as the 2.2.3 baseline on both 3.1.1 (clean under -W error) and 2.2.3 (repro/step3-all-fixed-*.log).

Sources

  • pandas migration guide, Copy-on-Write and chained assignment: https://pandas.pydata.org/docs/dev/user_guide/migration.html#copy-on-write-cow
  • String dtype / select_dtypes: https://pandas.pydata.org/docs/dev/user_guide/migration.html#string-migration-select-dtypes