Skip to content

Remove __array__() method#141

Merged
sgillies merged 3 commits into
mainfrom
remove-dunder-array
Mar 2, 2026
Merged

Remove __array__() method#141
sgillies merged 3 commits into
mainfrom
remove-dunder-array

Conversation

@sgillies

@sgillies sgillies commented Feb 28, 2026

Copy link
Copy Markdown
Member

This package shouldn't depend on Numpy. Instead, users should reshape their Numpy arrays created from Affine instances.

My second favorite approach would be to implement a .2d attribute (or a better name) so that users would do this: np.array(Affine().2d).

Instead, users should reshape their Numpy arrays.
@sgillies sgillies self-assigned this Feb 28, 2026

@mwtoews mwtoews left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, no big loss removing __array__. It's just a convenience when comparing against NumPy functions, as retained here in the tests.

This revert keeps the flat (dimensionless) structure the same as previous versions. I just have a suggestion to keep a test for the expected behavior of np.array(tfm) (i.e. that it doesn't return a 3x3 matrix).

Comment thread tests/test_numpy.py
ar = np.array(tfm)
assert ar.shape == (3, 3)
assert ar.dtype == np.float64
testing.assert_array_equal(ar, expected)

@mwtoews mwtoews Mar 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps retain a simple test that describes what's expected of numpy, specifically something like this:

def test_array():
    six_args = (np.arange(6) + 1) / 10
    tfm = Affine(*six_args)
    ar = np.array(tfm)
    assert ar.shape == (9,)
    testing.assert_array_equal(ar, np.concat([six_args, (0, 0, 1)]))

@sgillies sgillies merged commit bd709a4 into main Mar 2, 2026
8 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