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