Skip to content

AttributeError: 'Slice' object has no attribute 'value' when trying to access parts of np.array #809

@zznidar

Description

@zznidar

Trying to access parts of np.array using colons fails with AttributeError: 'Slice' object has no attribute 'value'

Simplified test

import pyscript
import numpy as np

@time_trigger("period(now, 4min)")
def simpleTest():
    test = np.array([[ [0, 0, 0], [255, 255, 255] ], [ [100, 150, 200], [50, 75, 100] ]])
    log.info(test)
    log.info(test.shape)
    test_cropped = test[:test.shape[0]*5//8, :, :]
    log.info(test_cropped)
    log.info(test_cropped.shape)

Repro steps

  1. Add the abovementioned simplified test to ~/config/pyscript in your Home Assistant
  2. Let it run
  3. Observe the logs (Settings -> System -> Logs)

Actual result

Running fails with error

2026-01-30 23:38:30.812 ERROR (MainThread) [custom_components.pyscript.file.watcher.simpleTest] Exception in <file.watcher.simpleTest> line 9:
        test_cropped = test[:test.shape[0]*5//8, :, :]
                            ^
AttributeError: 'Slice' object has no attribute 'value'

Expected result

It should not throw an error; instead, the result should be logged:

[[[  0   0   0]
  [255 255 255]]]
(1, 2, 3)

Version

Pyscript: Python Scripting for Home Assistant 1.7.0
Installation method Home Assistant OS
Core 2026.1.3
Supervisor 2026.01.1
Operating System 17.0
Frontend 20260107.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions