Is Mercator projection an affine trasformation? A practical example lead me to believe that a geographical projection, such as the Mercator projection, is an affine transformation.
However, when I checked on Wikipedia:

More generally, an affine transformation is an automorphism of an
affine space (Euclidean spaces are specific affine spaces), that is, a
function which maps an affine space onto itself while preserving both
the dimension of any affine subspaces (meaning that it sends points to
points, lines to lines, planes to planes, and so on) and the ratios of
the lengths of parallel line segments. Consequently, sets of parallel
affine subspaces remain parallel after an affine transformation.

This isn't true when it comes to Mercator: parallel lines on the surface on a Mercator map aren't paralell on the surface of a sphere.
However, in practical applications, affine transformations seem to be describe the mapping from a spherical surface to a plane and vice versa. Ie the documentation of the affine package within Python language, says:

Georeferenced raster datasets use affine transformations to map from
image coordinates to world coordinates. The affine.Affine.from_gdal()
class method helps convert GDAL GeoTransform, sequences of 6 numbers
in which the first and fourth are the x and y offsets and the second
and sixth are the x and y pixel sizes.

Ie this description claims that an affine transformation maps from planar to spherical surface.
What am I getting wrong here? Are there more than one definition of the term affine transformation (one mathematical, and one used by geographers), or am I making a mistake somewhere else?
 A: The Mercator projection maps a portion of a sphere  in $\mathbb R^3$ to a plane which is an affine space of dimension $2$. Consequently, it can’t be an affine transformation in the sense of Wikipedia definition.
However Mercator projection transforms in an conformal way the spherical coordinates, which belongs to an affine space of dimension $2$ to a plane.
We’re dealing with two coordinates systems of a sphere here.
A: I understand your quote

Georeferenced raster datasets use affine transformations to map from image coordinates to world coordinates

is from this Affine package. But I don't see any reference to Mercator there, so where did you get that from?
The quoted passage talks about affine transformations between image coordinates (on the plane) and world coordinates. Yes. But those would be another set of coordinates on a plane (on a planar map).
If you have a rectangular map of some small area, your image coordinates could be, for example, the pixel positions, with $x$ ranging from $0$ to $600$ and $y$ ranging from $0$ to $200$. To convert those coordinates to something globally meaningful, for example into EPSG:3857 coordinates, you could use an affine transformation. After the affine transformation, you have new $x'$ and $y'$ coordinates that you could call "world coordinates" because they would be coordinates on your 2D world map.
So is not the affine that is your problem; it is still the mathematical affine and it is between two planar coordinate systems. It is the world coordinates that is your problem.
Now how to transform those "world coordinates" into 3D Cartesian coordinates on the sphere, or into degrees of longitude and latitude, that's another transform that would indeed not be affine (except locally approximately).
image coordinates $\overset{f}\to$ world coordinates, $f$ affine, both coordinates on a flat plane
world coordinates $\overset{g}\to$ (latitude,longitude), $g$ for example Mercator projection, not affine
Does this clarify?
