Skip to content

Conversation

@amas0
Copy link
Collaborator

@amas0 amas0 commented Aug 7, 2025

Submission Checklist

  • Run unit tests
  • Declare copyright holder and open-source license: see below

Summary

Fixes #800.

New CSV parsing in #799 threw errors when attempting to parse csv content with no data. This can arise legitimately, for example, if iter_sampling=0 and save_warmup=False; which results in no draw lines (although the header line is present). In previous versions, empty data would result in empty numpy arrays. This change reverts the csv parsing of empty data to the previous behavior.

For clarity:

the cmdstanpy.utils.stancsv.csv_bytes_list_to_numpy(...) function now has the following behavior:

  • If an empty list is passed, an empty array with shape (0,) is returned
  • If an empty csv is passed where the number of columns can be inferred, an empty array with shape (0, num_cols) is returned

This PR also changes some stancsv unit tests to match the desired behavior and adds a test to test_sample for the case of no sampling draws.

Copyright and Licensing

Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): myself

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

Comment on lines +63 to +64
if not csv_bytes_list:
return np.empty((0,))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it's worth complicating the logic, but it would make sense to me if a completely empty list was illegal when includes_header=True. I don't think that would ever happen on a valid csv file, though

@WardBrian WardBrian merged commit 71d97ca into stan-dev:develop Aug 7, 2025
16 checks passed
@amas0 amas0 deleted the fix-empty-draws branch August 8, 2025 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New CSV reading fails when there are no draws

2 participants