@@ -164,6 +164,16 @@ def test_copy_masked_false(self):
164
164
class TestAsDataFrame (tests .IrisTest ):
165
165
"""Test conversion of 2D cubes to Pandas using as_data_frame()."""
166
166
167
+ def test_scalar_cube (self ):
168
+ cube = Cube (1.0 )
169
+ data_frame = iris .pandas .as_data_frame (cube )
170
+ expected_index = [0 ]
171
+ expected_columns = [0 ]
172
+ self .assertArrayEqual (data_frame , cube .data )
173
+ self .assertArrayEqual (data_frame .index , expected_index )
174
+ self .assertArrayEqual (data_frame .columns , expected_columns )
175
+ self .assertIsNone (data_frame .index .name )
176
+
167
177
def test_no_dim_coords (self ):
168
178
cube = Cube (np .array ([[0 , 1 , 2 , 3 , 4 ], [5 , 6 , 7 , 8 , 9 ]]), long_name = "foo" )
169
179
expected_index = [0 , 1 ]
@@ -323,6 +333,15 @@ class TestAsDataFrameNDim(tests.IrisTest):
323
333
def _activate_pandas_ndim (self , activate_pandas_ndim ):
324
334
pass
325
335
336
+ def test_scalar_cube (self ):
337
+ cube = Cube (1.0 , long_name = "foo" )
338
+ data_frame = iris .pandas .as_data_frame (cube )
339
+ expected_index = [0 ]
340
+ self .assertArrayEqual (data_frame .foo .values , cube .data )
341
+ self .assertEqual (data_frame .index .nlevels , 1 )
342
+ self .assertIsNone (data_frame .index .names [0 ])
343
+ self .assertArrayEqual (data_frame .index .levels [0 ], expected_index )
344
+
326
345
def test_no_dim_coords (self ):
327
346
cube = Cube (np .array ([[0 , 1 , 2 , 3 , 4 ], [5 , 6 , 7 , 8 , 9 ]]), long_name = "foo" )
328
347
expected_dim0 = np .repeat ([0 , 1 ], 5 )
0 commit comments