NCAS-CMS / NCAS-CMS/cf-python

datetime support not working for cf.Data made from a scalar

Open
#955 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug?
Dominant language
Python
Stars
150
Forks
23
Avg merge
1d 11h
Merged PRs (30d)
2

Description

I think this should return an integer year, but actually it returns a string (whose contents is incorrect):

>>> cf.Data(-182500.0,units='days since 0001-01-01 00:00:00',calendar='noleap').year               
<CF Data(): -0001-08-20 00:00:00 noleap>

I think it's because it's a scalar.

Maybe this is a bug which has been fixed since I last installed the packages (on jasmin)

>>> cf.environment(paths=False)
Platform: Linux-5.14.0-611.54.1.el9_7.x86_64-x86_64-with-glibc2.34
Python: 3.12.11
packaging: 25.0
numpy: 2.2.6
cfdm.core: 1.12.2.0
udunits2 library: /apps/jasmin/jaspy/miniforge_envs/jaspy3.12/mf3-25.3.0-3/envs/jaspy3.12-mf3-25.3.0-3-v20250704/lib/libudunits2.so.0
HDF5 library: 1.14.3
netcdf library: 4.9.2
netCDF4: 1.7.2
h5netcdf: 1.6.3
h5py: 3.13.0
zarr: 3.0.10
s3fs: 2025.5.1
scipy: 1.15.2
dask: 2025.5.1
cftime: 1.6.4
cfunits: 3.3.7
cfdm: 1.12.2.0
esmpy/ESMF: 8.8.1
psutil: 7.0.0
matplotlib: 3.10.3
cfplot: 3.4.0
cf: 3.18.0

Thanks

Jonathan

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the scalar cf.Data example from the issue and trace how its year property is calculated for the given noleap date. Check the scalar-specific datetime handling and verify that the result is the integer year -1 rather than an incorrect string.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.