# ERROR: LoadError: Python: IndexError: only integers, slices (\`:\`), ellipsis (\`...\`), numpy.newaxis (\`None\`) and integer or boolean arrays are valid indices

**URL:** <https://discourse.julialang.org/t/error-loaderror-python-indexerror-only-integers-slices-ellipsis-numpy-newaxis-none-and-integer-or-boolean-arrays-are-valid-indices/117028>\
**Category:** General Usage\
**Tags:** pythoncall\
**Created:** [July 14, 2024, 12:07pm UTC](https://discourse.julialang.org/t/error-loaderror-python-indexerror-only-integers-slices-ellipsis-numpy-newaxis-none-and-integer-or-boolean-arrays-are-valid-indices/117028 "2024-07-14T12:07:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 14, 2024, 12:07pm UTC](https://discourse.julialang.org/t/error-loaderror-python-indexerror-only-integers-slices-ellipsis-numpy-newaxis-none-and-integer-or-boolean-arrays-are-valid-indices/117028/1 "2024-07-14T12:07:07Z")

</div>

I am getting `ERROR: LoadError: Python: IndexError: only integers, slices (`:`), ellipsis (`…`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices Python stacktrace: none`  
I am using julia script that calls python code library. My julia code is 👇

```julia
cd("/home/raman/Pictures/MikiFor2to3/")
using Pkg, Interpolations, TensorOperations, DelimitedFiles
Pkg.activate(".")
Pkg.add(["CondaPkg", "PythonCall"])
using CondaPkg, PythonCall
CondaPkg.add(CondaPkg.PkgSpec.(["numpy", "scipy", "h5py", "matplotlib"]))
const sys = PythonCall.pyimport("sys")
sys.path.append(pwd())
const pyfiles = pyimport("pyfiles")
athena_read = pyimport("pyfiles.athena_read")
datafile ="./home/raman/Pictures/sane00.athinput/"
data = pyfiles.read_data("sane00.prim.01800.athdf", athinput="sane00.athinput")

theta = PyArray(data.metric.theta[1,:])
print(size(theta))

```

What should i do overcome this **indexing error** due to theta?

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [July 14, 2024, 12:16pm UTC](https://discourse.julialang.org/t/error-loaderror-python-indexerror-only-integers-slices-ellipsis-numpy-newaxis-none-and-integer-or-boolean-arrays-are-valid-indices/117028/2 "2024-07-14T12:16:36Z")

</div>

First determine which line of the code produces this error.

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [July 14, 2024, 12:55pm UTC](https://discourse.julialang.org/t/error-loaderror-python-indexerror-only-integers-slices-ellipsis-numpy-newaxis-none-and-integer-or-boolean-arrays-are-valid-indices/117028/3 "2024-07-14T12:55:23Z")

</div>

Posting the Julia code when the error is in your Python code is not that helpful. Best way to find the line causing the error is probably to run the python code in pure python (not called from Julia) and make sure that runs fine

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 14, 2024, 3:28pm UTC](https://discourse.julialang.org/t/error-loaderror-python-indexerror-only-integers-slices-ellipsis-numpy-newaxis-none-and-integer-or-boolean-arrays-are-valid-indices/117028/4 "2024-07-14T15:28:55Z")

</div>

Error is caused by last line defining variable **theta**.

```julia
julia> cd("/home/raman/Pictures/MikiFor2to3/")

julia> using Pkg, Interpolations, TensorOperations, DelimitedFiles

julia> Pkg.activate(".")
  Activating project at `~/Pictures/MikiFor2to3`

julia> Pkg.add(["CondaPkg", "PythonCall"])
   Resolving package versions...
  No Changes to `~/Pictures/MikiFor2to3/Project.toml`
  No Changes to `~/Pictures/MikiFor2to3/Manifest.toml`

julia> using CondaPkg, PythonCall

julia> CondaPkg.add(CondaPkg.PkgSpec.(["numpy", "scipy", "h5py", "matplotlib"]))

    CondaPkg Found dependencies: /home/raman/Pictures/MikiFor2to3/CondaPkg.toml
    CondaPkg Found dependencies: /home/raman/.julia/packages/PythonCall/S5MOg/CondaPkg.toml
    CondaPkg Found dependencies: /home/raman/.julia/environments/v1.10/CondaPkg.toml
    CondaPkg Dependencies already up to date

julia> const sys = PythonCall.pyimport("sys")
Python: <module 'sys' (built-in)>

julia> sys.path.append(pwd())
Python: None

julia> const pyfiles = pyimport("pyfiles")
Python: <module 'pyfiles' from '/home/raman/Pictures/MikiFor2to3/pyfiles/ __init__.py'>

julia> athena_read = pyimport("pyfiles.athena_read")
Python: <module 'pyfiles.athena_read' from '/home/raman/Pictures/MikiFor2to3/pyfiles/athena_read.py'>

julia> datafile ="./home/raman/Pictures/sane00.athinput/"
"./home/raman/Pictures/sane00.athinput/"

julia> data = pyfiles.read_data("sane00.prim.01800.athdf", athinput="sane00.athinput")
Python: <pyfiles.read_data.read_data object at 0x7f8ac9a6f740>

julia> theta = PyArray(data.metric.theta[1,:])
ERROR: Python: IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
Python stacktrace: none
Stacktrace:
 [1] pythrow()
   @ PythonCall.Core ~/.julia/packages/PythonCall/S5MOg/src/Core/err.jl:92
 [2] errcheck
   @ ~/.julia/packages/PythonCall/S5MOg/src/Core/err.jl:10 [inlined]
 [3] pygetitem(x::Py, k::Tuple{Int64, Colon})
   @ PythonCall.Core ~/.julia/packages/PythonCall/S5MOg/src/Core/builtins.jl:171
 [4] getindex(::Py, ::Int64, ::Function)
   @ PythonCall.Core ~/.julia/packages/PythonCall/S5MOg/src/Core/Py.jl:293
 [5] top-level scope
   @ REPL[13]:1

```

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [July 14, 2024, 6:48pm UTC](https://discourse.julialang.org/t/error-loaderror-python-indexerror-only-integers-slices-ellipsis-numpy-newaxis-none-and-integer-or-boolean-arrays-are-valid-indices/117028/5 "2024-07-14T18:48:38Z")

</div>

The Julia `:` is not converted to anything very useful currently when passed to Python. You can get a Python `:` with `pyslice(nothing)`.
