Skip to content

[Repo Assist] Fix DateTime key formatting in FSI output — closes #95#633

Merged
dsyme merged 2 commits intomasterfrom
repo-assist/fix-issue-95-datetime-key-formatting-cd6b3238abd5c3f8
Mar 17, 2026
Merged

[Repo Assist] Fix DateTime key formatting in FSI output — closes #95#633
dsyme merged 2 commits intomasterfrom
repo-assist/fix-issue-95-datetime-key-formatting-cd6b3238abd5c3f8

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated fix from Repo Assist.

Closes #95

Root cause

Series.FormatStrings, Frame.FormatStrings, and Series.ToString() all format index keys using .ToString() directly. For DateTime values, this always includes the time component — even when it is 00:00:00 — producing noisy output like 1/1/2023 12:00:00 AM for every row of a day-granularity time series.

The CSV exporter in FrameUtils.fs already applied a per-key rule: if dt.TimeOfDay = TimeSpan.Zero format as date-only ("d"). The FSI prettyprint code was missing this behaviour.

Fix

Added a Formatting.formatKey helper to Common.fs:

let formatKey (key:obj) =
  match key with
  | :? DateTime as dt when dt.TimeOfDay = TimeSpan.Zero ->
      dt.ToString("d", Globalization.CultureInfo.CurrentCulture)
  | _ -> key.ToString()
```

Then wired it in to the three call sites:

- `Frame.fs` → `getLevel` (row/column header rendering)
- `Series.fs` → `getLevel` (table rendering) and `Series.ToString()` (inline FSI output)

## Before / After

**Before:**
```
1/1/2023 12:00:00 AM -> 1.5
1/2/2023 12:00:00 AM -> 2.1
1/3/2023 12:00:00 AM -> 3.7
```

**After:**
```
1/1/2023 -> 1.5
1/2/2023 -> 2.1
1/3/2023 -> 3.7

DateTime keys with a non-zero time component are unaffected.

Trade-offs

  • Per-key decision (not "all-or-nothing"): a series with mixed date-only and datetime keys will have narrower formatting for the date-only rows. In practice, mixed series are rare.
  • Uses CultureInfo.CurrentCulture for locale-appropriate formatting, matching the CSV exporter.
  • Zero extra allocations for non-DateTime keys.

Test Status

  • ✅ 4 new regression tests added to tests/Deedle.Tests/Formatting.fs
  • ✅ All 592 tests pass (dotnet test tests/Deedle.Tests/Deedle.Tests.fsproj -c Release)
  • ✅ Build succeeded with 0 errors

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@30f2254f2a7a944da1224df45d181a3f8faefd0d

When pretty-printing Series and Frame values in F# Interactive (FSI),
DateTime keys whose time component is 00:00:00 now format as date-only
(using the short-date 'd' format from the current culture), matching the
behaviour already present in SaveCsv.

Previously, a Series<DateTime, float> with day-granularity keys would
print keys as '1/1/2023 12:00:00 AM' on every row, cluttering the output.
After this fix they print as '1/1/2023'.

Changes:
- Added Formatting.formatKey helper in Common.fs that applies the date-only
  rule to DateTime values with TimeOfDay = TimeSpan.Zero.
- Used Formatting.formatKey in the getLevel helper in both Frame.fs and
  Series.fs (FormatStrings table rendering).
- Used Formatting.formatKey in Series.ToString() (inline FSI representation).
- Added 4 regression tests in tests/Deedle.Tests/Formatting.fs.

Fixes #95.

Co-authored-by: Copilot <[email protected]>
@dsyme dsyme marked this pull request as ready for review March 17, 2026 00:50
@dsyme dsyme merged commit b8465fc into master Mar 17, 2026
1 of 2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-95-datetime-key-formatting-cd6b3238abd5c3f8 branch March 17, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve the FSI prettyprint output of Frames with DateTime keys

1 participant