Skip to content

[WIP] Fix failing GitHub Actions job due to import and NumPy issues#188

Merged
telegraphic merged 8 commits intomasterfrom
copilot/fix-github-actions-job-errors
Apr 30, 2026
Merged

[WIP] Fix failing GitHub Actions job due to import and NumPy issues#188
telegraphic merged 8 commits intomasterfrom
copilot/fix-github-actions-job-errors

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 30, 2026

  • Fix 1: Guard pkg_resources import in hickle/legacy_v3/hickle.py with try/except (ImportError for broad compatibility); provide a stub get_distribution that raises DistributionNotFound if called without setuptools
  • Fix 2: Replace np.array(string_data, copy=False) with np.asarray(string_data) in hickle/loaders/load_numpy.py create_np_array_dataset for NumPy 2.0 compatibility
  • Astropy test uses master's .tobytes() fix (from PR replace ndarray.tostring with ndarray.tobytes #187); no change needed here
Original prompt

Create a PR against the master branch of telegraphic/hickle to fix the failing GitHub Actions job.

Context

Failures to address

  1. Legacy v3 loader import failure
  • Error: ModuleNotFoundError: No module named 'pkg_resources'
  • Location: hickle/legacy_v3/hickle.py (top-level import)
  • Fix: Make pkg_resources optional. Guard the import with try/except and ensure any later usage of get_distribution is also guarded.
  1. NumPy 2.0+ incompatibility
  • Error: ValueError: Unable to avoid copy while creating an array as requested.
  • Guidance indicates np.array(obj, copy=False) should be replaced with np.asarray(obj).
  • Locations in hickle/loaders/load_numpy.py:
    • create_np_array_dataset string scalar path uses np.array(..., copy=False)
    • load_ndarray_dataset string dtype path uses np.array(..., copy=False, dtype=...)
  • Fix: Replace those calls with np.asarray(...) (keeping dtype where needed) or otherwise allow copies when unavoidable, while preserving behavior for NumPy 1.x.
  1. Astropy test failure due to removed .tostring()
  • Error: AttributeError: 'numpy.str_' object has no attribute 'tostring'
  • Location: hickle/tests/test_06_load_astropy.py around assertions comparing reloaded.value[index].tostring().
  • Fix: Update the test to compare values in a way that works across NumPy versions (e.g., str(...) comparison or .tobytes() where appropriate).

Acceptance criteria

  • CI tests pass for the failing job.
  • Changes are minimal and focused.
  • Include/adjust tests where appropriate.
  • Add brief PR description summarizing root causes (pkg_resources optional, NumPy copy keyword change, astropy tostring removal).

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The job is failing for two independent reasons:

  1. Legacy v3 loader crashes because pkg_resources is missing
  • In the logs, importing hickle/legacy_v3/hickle.py fails at from pkg_resources import get_distribution, DistributionNotFound (hickle/legacy_v3/hickle.py:28 at ref 17d0832db676f4acec086f07141845b7aaab4403).
  • Modern Python environments can omit setuptools (which provides pkg_resources), so this import is no longer safe.

Fix

Make pkg_resources optional in the legacy loader (best: don’t require it at import time). In hickle/legacy_v3/hickle.py (ref 17d0832...), change the top-level import to a guarded import:

# hickle/legacy_v3/hickle.py

try:
    from pkg_resources import get_distribution, DistributionNotFound
except ModuleNotFoundError:  # pkg_resources is provided by setuptools, may be absent
    get_distribution = None
    class DistributionNotFound(Exception):
        pass

If get_distribution(...) is used later in that file, gate it like:

if get_distribution is not None:
    # existing logic using get_distribution
    ...

This allows legacy-v3 loading to proceed instead of erroring before hkl.load() can emit the expected “Using legacy load…” warning.

(Alternative/workflow-only mitigation: ensure setuptools is installed in the test env, but code should still be robust.)


  1. NumPy 2.0+ incompatibility: np.array(..., copy=False) now raises
    Several tests fail with:

ValueError: Unable to avoid copy while creating an array as requested. If using np.array(obj, copy=False) replace it with np.asarray(obj) ...

The culprit is in hickle/loaders/load_numpy.py:

  • load_ndarray_dataset() returns np.array(string_data, copy=False, dtype=dtype) for string dtypes (line ~235 in the retrieved file at ref 17d0832...).
  • create_np_array_dataset() also uses np.array(string_data, copy=False) during string scalar dumping (line ~105).

Fix

Replace np.array(..., copy=False) with np.asarray(...) (or allow copies when needed). Suggested minimal patches:

A. In load_ndarray_dataset (string path):

# hickle/loaders/load_numpy.py

if "str" in dtype.name:
    string_data = h_node[()]
    if h_node.dtype.itemsize <= 1 or 'bytes' not in h_node.dtype.name:
        string_data = bytes(string_data).decode("utf8")
    # NumPy 2.0: np.array(..., copy=False) may raise. Use asarray.
    return np.asarray(string_data, dtype=dtype)

B. In create_np_array_dataset (scalar string path):
Current code does:

string_data = np.array(string_data, copy=False)

Change to:

string_data = np.asarray(string_data)

That should address the three NumPy-related failures reported in the summary:

  • test_load_hickle_4_0_X_string
  • test_listlike_dataset
  • `test_crea...

This pull request was created from Copilot chat.

…astropy tostring

Agent-Logs-Url: https://github.com/telegraphic/hickle/sessions/6e186643-c2fb-4c1d-9205-58dfb74a17f1

Co-authored-by: telegraphic <713251+telegraphic@users.noreply.github.com>
Copilot AI and others added 2 commits April 30, 2026 02:32
…umpy copy=False fixes

Agent-Logs-Url: https://github.com/telegraphic/hickle/sessions/5ea2752b-a76b-43ce-9b45-2ebee1cfe815

Co-authored-by: telegraphic <713251+telegraphic@users.noreply.github.com>
…ompatibility

Agent-Logs-Url: https://github.com/telegraphic/hickle/sessions/5ea2752b-a76b-43ce-9b45-2ebee1cfe815

Co-authored-by: telegraphic <713251+telegraphic@users.noreply.github.com>
Copy link
Copy Markdown
Owner

@telegraphic telegraphic left a comment

Choose a reason for hiding this comment

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

LGTM

@telegraphic telegraphic marked this pull request as ready for review April 30, 2026 02:37
Copilot AI and others added 3 commits April 30, 2026 03:19
…rrors

ci: fix Codecov rate-limit failures — upgrade to v5, single-job upload
@telegraphic telegraphic merged commit 2ba8c66 into master Apr 30, 2026
22 of 28 checks passed
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.

2 participants