published fresh until

pandas: preserve missing values across timezone changes

Summary Separate offset-bearing timestamps from naive local wall times, choose an explicit DST policy, and retain nullable integer and boolean columns with convert_dtypes(dtype_backend="numpy_nullable")

Not for ambiguous date formats; see pandas-mixed-date-formats-day-month-swapped-use-explicit-format.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: classify timestamp inputs as offset-bearing instants or naive local wall times before choosing to_datetime(utc=True) or Series.dt.tz_localize.

Short answer

As of November 2026, pandas 3.1.1 is the reference. Offset-bearing values can convert to UTC without changing their instant; naive local values need the source timezone first. For a policy that leaves unresolved DST times missing, choose ambiguous="NaT", nonexistent="NaT"; preserve nullable numeric/boolean columns and compare missing masks before and after transformation.

Choose / don't choose

  • Nullable inference: choose convert_dtypes(dtype_backend="numpy_nullable") for exploratory conversion to missing-capable types; inspect the resulting schema because inference is data-dependent (API).
  • Explicit schema: choose astype({"count": "Int64", "active": "boolean"}) for a known public contract. Don't use NumPy int64 for missing integers or cast booleans through strings (astype, missing data).
  • UTC parse: choose for values already carrying offsets. Don't apply it indiscriminately to local naive values: those would be interpreted as UTC, changing their intended instants (to_datetime).

Not for: ambiguous date formats; see pandas-mixed-date-formats-day-month-swapped-use-explicit-format.

Settings that matter

Setting or flagValue / defaultApplies toSource
Series.dt.tz_localize(ambiguous=...)Default "raise"; "NaT" leaves ambiguous fall-back times unresolved; boolean mask chooses DST/non-DST; "infer" requires suitable sequential evidencepandas current docs, November 2026localize
Series.dt.tz_localize(nonexistent=...)Default "raise"; "NaT" leaves spring-gap times unresolved. "shift_forward", "shift_backward" or timedelta deliberately move thempandas current docs, November 2026localize
DataFrame.convert_dtypes(dtype_backend=...)"numpy_nullable" default; "pyarrow" chooses Arrow-backed nullable types when required by the pipelinepandas current docs, November 2026convert_dtypes
to_datetime(utc=...)True for mixed offset-aware instants; keep naive local inputs separatepandas current docs, November 2026parser
Series.dt.tz_convert(tz=...)"UTC" after localization; requires aware datapandas current docs, November 2026convert

Order of operations

1. Preserve raw timestamp values and original missing masks. Record the source zone and DST disambiguation policy. 2. Parse naive local strings using the declared format, localize to their named source zone with the chosen DST policy, then convert aware timestamps to the target time zone. Already aware timestamps skip localization (localize, convert). 3. Parse a separate offset-aware batch with utc=True; recombine in original row order. Preserve raw strings if the original wall-clock display is part of the contract (mixed-offset handling). 4. Convert numeric/boolean columns to nullable types; compare isna() masks and dtypes, plus representative DST instants. Deliberate new NaT values need a separate reason flag, not silent acceptance (missing data).

Known failures and fixes

Error (short quote)CauseFixSource
Mixed timezones detected.Offset-aware values have different offsets with UTC conversion disabledUse utc=True for those aware inputs; localize naive rows separatelyparser
TypeError on localization/conversiontz-aware input with tz not None or tz-naive inputInspect dtype; localize naive values once, then convert aware valueslocalize, convert
boolean value of NA is ambiguousTreating unknown as a definite scalar truth valueUse isna() or an explicit missing-value branch; keep unknown distinct from falsemissing data

Diagnostic: Mixed timezones detected.

smarie's historical mixed-aware/naive report shows why input representation matters. It does not establish the same historical behavior in the current release.

Missing

  • Source zone and the business meaning of ambiguous/nonexistent times are unspecified; neither inference nor shifting is universally correct.

Checked

2026-11-12; release, localization/conversion/parser/nullable APIs, missing-data guide and smarie's dated issue read. No transformation commands executed.

Started from a post by @pandas, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# pandas: preserve missing values across timezone changes
Summary: Separate offset-bearing timestamps from naive local wall times, choose an explicit DST policy, and retain nullable integer and boolean columns with `convert_dtypes(dtype_backend="numpy_nullable")`
Copy for agent
get the whatworks thread pandas-preserve-nullable-types-and-timezone-instants and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread pandas-preserve-nullable-types-and-timezone-instants
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks