@@ -3528,6 +3528,34 @@ def test_to_dataframe_0length(self) -> None:
3528
3528
assert len (actual ) == 0
3529
3529
assert_array_equal (actual .index .names , list ("ABC" ))
3530
3530
3531
+ @pytest .mark .parametrize (
3532
+ "x_dtype,y_dtype,v_dtype" ,
3533
+ [
3534
+ (np .uint32 , np .float32 , np .uint32 ),
3535
+ (np .int16 , np .float64 , np .int64 ),
3536
+ (np .uint8 , np .float32 , np .uint16 ),
3537
+ (np .int32 , np .float32 , np .int8 ),
3538
+ ],
3539
+ )
3540
+ def test_to_dataframe_coord_dtypes_2d (self , x_dtype , y_dtype , v_dtype ) -> None :
3541
+ x = np .array ([1 ], dtype = x_dtype )
3542
+ y = np .array ([1.0 ], dtype = y_dtype )
3543
+ v = np .array ([[42 ]], dtype = v_dtype )
3544
+
3545
+ da = DataArray (v , dims = ["x" , "y" ], coords = {"x" : x , "y" : y })
3546
+ df = da .to_dataframe (name = "v" ).reset_index ()
3547
+
3548
+ # Check that coordinate dtypes are preserved
3549
+ assert df ["x" ].dtype == np .dtype (x_dtype ), (
3550
+ f"x coord: expected { x_dtype } , got { df ['x' ].dtype } "
3551
+ )
3552
+ assert df ["y" ].dtype == np .dtype (y_dtype ), (
3553
+ f"y coord: expected { y_dtype } , got { df ['y' ].dtype } "
3554
+ )
3555
+ assert df ["v" ].dtype == np .dtype (v_dtype ), (
3556
+ f"v data: expected { v_dtype } , got { df ['v' ].dtype } "
3557
+ )
3558
+
3531
3559
@requires_dask_expr
3532
3560
@requires_dask
3533
3561
@pytest .mark .xfail (not has_dask_ge_2025_1_0 , reason = "dask-expr is broken" )
0 commit comments