Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Expected behavior and actual behavior.

I'm currently updating some dependencies for a library (github.com/shuttle1987/pyidw) and I have run into the following issue with existing code breaking when updating the version of rasterio.

(The regression I'm trying to fix can be found here: github.com/shuttle1987/pyidw/issues/1)

Steps to reproduce the problem.

In the existing code lists of values were passed to .index like so:

    with rasterio.open(resized_raster_name) as baseRasterFile:
        inputPoints = gpd.read_file(input_point_shapefile)
        # obser_df stands for observation_dataframe, lat, lon, data_value for each station will be stored here.
        obser_df = pd.DataFrame()
        obser_df['station_name'] = inputPoints.iloc[:, 0]


        # create two list of indexes of station longitude, latitude in elevation raster file.
        lons, lats = baseRasterFile.index(
            [lon for lon in inputPoints.geometry.x],
            [lat for lat in inputPoints.geometry.y])

This used to work but now creates a type error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[6], line 1
----> 1 idw.idw_interpolation(
      2     input_point_shapefile="Bangladesh_Temperature.shp",
      3     extent_shapefile="Bangladesh_Border.shp",
      4     column_name="Max_Temp",
      5     power=2,
      6     search_radius=10,
      7     output_resolution=250,
      8 )

File ~/Desktop/experimental-code/.venv/lib/python3.12/site-packages/pyidw/idw.py:191, in idw_interpolation(input_point_shapefile, extent_shapefile, column_name, power, search_radius, output_resolution)
    188 obser_df['station_name'] = inputPoints.iloc[:, 0]
    190 # create two list of indexes of station longitude, latitude in elevation raster file.
--> 191 lons, lats = baseRasterFile.index(
    192     [lon for lon in inputPoints.geometry.x],
    193     [lat for lat in inputPoints.geometry.y])
    194 obser_df['lon_index'] = lons
    195 obser_df['lat_index'] = lats

File ~/Desktop/experimental-code/.venv/lib/python3.12/site-packages/rasterio/transform.py:135, in TransformMethodsMixin.index(self, x, y, z, op, precision, transform_method, **rpc_options)
    133 if not transform:
    134     raise AttributeError(f"Dataset has no {transform_method}")
--> 135 return tuple(int(val) for val in rowcol(transform, x, y, zs=z, op=op, **rpc_options))

File ~/Desktop/experimental-code/.venv/lib/python3.12/site-packages/rasterio/transform.py:135, in <genexpr>(.0)
    133 if not transform:
    134     raise AttributeError(f"Dataset has no {transform_method}")
--> 135 return tuple(int(val) for val in rowcol(transform, x, y, zs=z, op=op, **rpc_options))

TypeError: only length-1 arrays can be converted to Python scalars

I can see that the breakage in the source code above was caused by the changes in this commit:

099b33c

Where this line:

        return rowcol(transform, x, y, zs=z, op=op, **rpc_options)

was changed to this:

        return tuple(int(val) for val in rowcol(transform, x, y, zs=z, op=op, **rpc_options))

Given the bump in the patch version it was somewhat surprising that backwards compatibility was broken. Now I could pin rasterio to an older version before this change was made but I'd much rather stay up to date with rasterio packages, what should I modify in my existing code here to keep up to date with the changes in the upstream library?

Environment Information

$ uv run python -c "import rasterio; rasterio.show_versions()"
rasterio info:
  rasterio: 1.4.3
      GDAL: 3.9.3
      PROJ: 9.4.1
      GEOS: 3.11.1
 PROJ DATA: /home/janis/Desktop/pyidw/.venv/lib/python3.12/site-packages/rasterio/proj_data
 GDAL DATA: /home/janis/Desktop/pyidw/.venv/lib/python3.12/site-packages/rasterio/gdal_data

System:
    python: 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0]
executable: /home/janis/Desktop/pyidw/.venv/bin/python3
   machine: Linux-6.14.0-27-generic-x86_64-with-glibc2.39

Python deps:
    affine: 2.4.0
     attrs: 25.3.0
   certifi: 2025.08.03
     click: 8.2.1
     cligj: 0.7.2
    cython: None
     numpy: 2.3.2
click-plugins: None
setuptools: None

Installation Method

I installed rasterio via the uv package manager.

You must be logged in to vote

@shuttle1987 .index() accidentally accepted sequences of x and y input before, but it was never intended. The documentation made it pretty clear, I think, that the function was intended to work on scalars. We've removed the unintended and undefined behavior. I call that a bug fix.

Replies: 1 comment · 1 reply

Comment options

@shuttle1987 .index() accidentally accepted sequences of x and y input before, but it was never intended. The documentation made it pretty clear, I think, that the function was intended to work on scalars. We've removed the unintended and undefined behavior. I call that a bug fix.

You must be logged in to vote
1 reply
@shuttle1987
Comment options

Thanks for the explanation that the library I forked was using some sort of unintended/undefined behavior that happened to work with an older version of the library. What I did like about before is that it seemed to vectorize the code which was nice. I'm curious what the best way to change the calling code would be to get a similar result?

Of course I could turn these statements into a loop if there's no other way to achieve this. Any suggestions?

Answer selected by shuttle1987
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3382 on August 20, 2025 18:06.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.