@@ -334,6 +334,153 @@ def test_multiindex_interval_datetimes(self, tmp_excel):
334
334
)
335
335
tm .assert_frame_equal (result , expected )
336
336
337
+ def test_read_write_with_notes (self , tmp_excel , ext ):
338
+ if ext in ["xlsm" , "xlsx" ]:
339
+ expected = DataFrame (
340
+ [
341
+ ["note 1" , "note 2" , "note 3" ],
342
+ ["note 1" , "note 2" , "note 3" ],
343
+ ["note 1" , "note 2" , "note 3" ],
344
+ ]
345
+ )
346
+ df = DataFrame (
347
+ [
348
+ [1 , 100 , 200 ],
349
+ [2 , 200 , 300 ],
350
+ [3 , 300 , 400 ],
351
+ ]
352
+ )
353
+ df .style .set_tooltips (expected ).to_excel (tmp_excel )
354
+ result = DataFrame ()
355
+ result = pd .read_excel (tmp_excel , notes = result )
356
+ tm .assert_frame_equal (result , expected )
357
+
358
+ def test_read_write_with_notes_trim_rows (self , tmp_excel , ext ):
359
+ if ext in ["xlsm" , "xlsx" ]:
360
+ expected = DataFrame (
361
+ [
362
+ ["" , "" , "" ],
363
+ ["note 1" , "note 2" , "note3" ],
364
+ ["" , "" , "" ],
365
+ ]
366
+ )
367
+ df = DataFrame (
368
+ [
369
+ [1 , 100 , 200 ],
370
+ [2 , 200 , 300 ],
371
+ [3 , 300 , 400 ],
372
+ ]
373
+ )
374
+ df .style .set_tooltips (expected ).to_excel (tmp_excel )
375
+ result = DataFrame ()
376
+ result = pd .read_excel (tmp_excel , notes = result )
377
+ tm .assert_frame_equal (result , expected )
378
+
379
+ def test_read_write_with_notes_trim_columns (self , tmp_excel , ext ):
380
+ if ext in ["xlsm" , "xlsx" ]:
381
+ expected = DataFrame (
382
+ [
383
+ ["" , "note 2" , "" ],
384
+ ["" , "note 2" , "" ],
385
+ ["" , "note 2" , "" ],
386
+ ]
387
+ )
388
+ df = DataFrame (
389
+ [
390
+ [1 , 100 , 200 ],
391
+ [2 , 200 , 300 ],
392
+ [3 , 300 , 400 ],
393
+ ]
394
+ )
395
+ df .style .set_tooltips (expected ).to_excel (tmp_excel )
396
+ result = DataFrame ()
397
+ result = pd .read_excel (tmp_excel , notes = result )
398
+ tm .assert_frame_equal (result , expected )
399
+
400
+ def test_read_write_with_notes_trim_rows_and_columns (self , tmp_excel , ext ):
401
+ if ext in ["xlsm" , "xlsx" ]:
402
+ expected = DataFrame (
403
+ [
404
+ ["" , "" , "" ],
405
+ ["" , "note 2" , "" ],
406
+ ["" , "" , "" ],
407
+ ]
408
+ )
409
+ df = DataFrame (
410
+ [
411
+ [1 , 100 , 200 ],
412
+ [2 , 200 , 300 ],
413
+ [3 , 300 , 400 ],
414
+ ]
415
+ )
416
+ df .style .set_tooltips (expected ).to_excel (tmp_excel )
417
+ result = DataFrame ()
418
+ result = pd .read_excel (tmp_excel , notes = result )
419
+ tm .assert_frame_equal (result , expected )
420
+
421
+ def test_read_write_with_notes_empty_comments_no_trim (self , tmp_excel , ext ):
422
+ if ext in ["xlsm" , "xlsx" ]:
423
+ expected = DataFrame (
424
+ [
425
+ ["note 1" , "" , "" ],
426
+ ["" , "" , "" ],
427
+ ["" , "" , "note 3" ],
428
+ ]
429
+ )
430
+ df = DataFrame (
431
+ [
432
+ [1 , 100 , 200 ],
433
+ [2 , 200 , 300 ],
434
+ [3 , 300 , 400 ],
435
+ ]
436
+ )
437
+ df .style .set_tooltips (expected ).to_excel (tmp_excel )
438
+ result = DataFrame ()
439
+ result = pd .read_excel (tmp_excel , notes = result )
440
+ tm .assert_frame_equal (result , expected )
441
+
442
+ def test_read_write_with_notes_smaller_dimensions (self , tmp_excel , ext ):
443
+ if ext in ["xlsm" , "xlsx" ]:
444
+ expected = DataFrame (
445
+ [
446
+ ["note 1" , "note 2" ],
447
+ ["note 1" , "note 2" ],
448
+ ]
449
+ )
450
+ df = DataFrame (
451
+ [
452
+ [1 , 100 , 200 ],
453
+ [2 , 200 , 300 ],
454
+ [3 , 300 , 400 ],
455
+ ]
456
+ )
457
+ df .style .set_tooltips (expected ).to_excel (tmp_excel )
458
+ result = DataFrame ()
459
+ result = pd .read_excel (tmp_excel , notes = result )
460
+ tm .assert_frame_equal (result , expected )
461
+
462
+ def test_read_write_with_notes_bigger_dimensions (self , tmp_excel , ext ):
463
+ if ext in ["xlsm" , "xlsx" ]:
464
+ expected = DataFrame (
465
+ [
466
+ ["note 1" , "note 2" , "note 3" , "note 4" ],
467
+ ["note 1" , "note 2" , "note 3" , "note 4" ],
468
+ ["note 1" , "note 2" , "note 3" , "note 4" ],
469
+ ["note 1" , "note 2" , "note 3" , "note 4" ],
470
+ ]
471
+ )
472
+ df = DataFrame (
473
+ [
474
+ [1 , 100 , 200 ],
475
+ [2 , 200 , 300 ],
476
+ [3 , 300 , 400 ],
477
+ ]
478
+ )
479
+ df .style .set_tooltips (expected ).to_excel (tmp_excel )
480
+ result = DataFrame ()
481
+ result = pd .read_excel (tmp_excel , notes = result )
482
+ tm .assert_frame_equal (result , expected )
483
+
337
484
338
485
@pytest .mark .parametrize (
339
486
"engine,ext" ,
0 commit comments