Skip to content

Implement Raster.astype#423

Draft
Copilot wants to merge 2 commits intodevelopfrom
copilot/implement-raster-astype
Draft

Implement Raster.astype#423
Copilot wants to merge 2 commits intodevelopfrom
copilot/implement-raster-astype

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

Raster lacked an astype method, forcing direct array mutation (raster.arr = raster.arr.astype("float32")) and breaking method chaining.

Changes

  • Raster.astype(dtype) — new method returning a new Raster with the array cast to the given dtype; metadata is preserved unchanged. Follows the same copy-and-modify pattern as abs(), clamp(), etc.
  • DTypeLike added to TYPE_CHECKING imports in raster.py
  • TestAstype test class added covering dtype conversion, value preservation, and subclass return type

Usage

slope_raster = slope_raster.astype("float32")

# Or in a chain
result = raster.clamp(a_min=0).astype("float32")
Original prompt

This section details on the original issue you should resolve

<issue_title>Implement Raster.astype</issue_title>
<issue_description>So we can do

slope_raster = slope_raster.astype("float32")

Instead of

slope_raster.arr = slope_raster.arr.astype("float32")

Useful for method chaining. Similar to to_crs and other cleanup methods</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement Raster.astype for method chaining Implement Raster.astype Feb 23, 2026
@t-t-sonarqube
Copy link

t-t-sonarqube bot commented Feb 23, 2026

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.

Implement Raster.astype

2 participants