Repository: taxprofiler/taxpasta

Issue:
[BUG] Adding taxon names to the output fails
### Is there an existing issue for this?

- [X] I have searched the existing issues

### Problem description

Hi, thank you for a great tool! 

I am getting: AttributeError: 'DataFrame' object has no attribute 'name' error when trying to merge reports from taxprofiler (kraken2, bracken, diamond). When i run without the add parameters it works. 
It have been testing on both the same reports from the older version of taxprofiler 1.0.1 and the new 1.1.0 but i get the same error. It might to be linked to the update of taxpasta as version 0.3.0 worked for me before i updated it. 

Thank you for the help! 

### Code sample

Code run:

```bash
taxpasta merge -p diamond -o diamond_Diamond_230321.tsv --taxonomy /medstore/databases/taxprofiler/databases/taxpasta_taxonomy/taxdump --ignore-errors --add-id-lineage --add-lineage --add-name --add-rank --add-rank-lineage  KV23-5721-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.diamond.tsv KV19-4396-moc-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.diamond.tsv KV19-4396-neg-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.diamond.tsv KV19-4396-moc-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.diamond.tsv KV23-5721-moc-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.diamond.tsv KV20-1130-posEV-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.diamond.tsv KV19-4396-neg-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.diamond.tsv KV23-5721-moc-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.diamond.tsv KV23-5721-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.diamond.tsv
```

Traceback:

```text
[09:47:34] WARNING  The merged profiles contained different taxa. Additional zeroes were    sample_handling_application.py:142
                    introduced for missing taxa.
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/xabras/.conda/envs/TaxPasta/lib/python3.11/site-packages/taxpasta/infrastructure/cli/merge │
│ .py:451 in merge                                                                                 │
│                                                                                                  │
│   448 │   result = handling_app.merge_samples(samples, wide_format)                              │
│   449 │                                                                                          │
│   450 │   if valid_output_format is not WideObservationTableFileFormat.BIOM:                     │
│ ❱ 451 │   │   result = command.execute(result)                                                   │
│   452 │                                                                                          │
│   453 │   logger.info("Write result to '%s'.", str(output))                                      │
│   454 │   if wide_format:                                                                        │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │        add_id_lineage = True                                                                 │ │
│ │           add_lineage = True                                                                 │ │
│ │              add_name = True                                                                 │ │
│ │              add_rank = True                                                                 │ │
│ │      add_rank_lineage = True                                                                 │ │
│ │               command = AddTaxInfoCommand(                                                   │ │
│ │                         │                                                                    │ │
│ │                         taxonomy_service=<taxpasta.infrastructure.domain.service.taxopy_tax… │ │
│ │                         object at 0x7f9e7a14a990>,                                           │ │
│ │                         │   summarise_at=None,                                               │ │
│ │                         │   add_name=True,                                                   │ │
│ │                         │   add_rank=True,                                                   │ │
│ │                         │   add_lineage=True,                                                │ │
│ │                         │   add_id_lineage=True,                                             │ │
│ │                         │   add_rank_lineage=True                                            │ │
│ │                         )                                                                    │ │
│ │                  data = [                                                                    │ │
│ │                         │   (                                                                │ │
│ │                         │   │                                                                │ │
│ │                         'KV23-5721-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.di… │ │
│ │                         │   │                                                                │ │
│ │                         PosixPath('KV23-5721-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond… │ │
│ │                         │   ),                                                               │ │
│ │                         │   (                                                                │ │
│ │                         │   │                                                                │ │
│ │                         'KV19-4396-moc-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_23032… │ │
│ │                         │   │                                                                │ │
│ │                         PosixPath('KV19-4396-moc-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Dia… │ │
│ │                         │   ),                                                               │ │
│ │                         │   (                                                                │ │
│ │                         │   │                                                                │ │
│ │                         'KV19-4396-neg-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_23032… │ │
│ │                         │   │                                                                │ │
│ │                         PosixPath('KV19-4396-neg-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Dia… │ │
│ │                         │   ),                                                               │ │
│ │                         │   (                                                                │ │
│ │                         │   │                                                                │ │
│ │                         'KV19-4396-moc-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_23032… │ │
│ │                         │   │                                                                │ │
│ │                         PosixPath('KV19-4396-moc-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Dia… │ │
│ │                         │   ),                                                               │ │
│ │                         │   (                                                                │ │
│ │                         │   │                                                                │ │
│ │                         'KV23-5721-moc-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_23032… │ │
│ │                         │   │                                                                │ │
│ │                         PosixPath('KV23-5721-moc-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Dia… │ │
│ │                         │   ),                                                               │ │
│ │                         │   (                                                                │ │
│ │                         │   │                                                                │ │
│ │                         'KV20-1130-posEV-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230… │ │
│ │                         │   │                                                                │ │
│ │                         PosixPath('KV20-1130-posEV-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_D… │ │
│ │                         │   ),                                                               │ │
│ │                         │   (                                                                │ │
│ │                         │   │                                                                │ │
│ │                         'KV19-4396-neg-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_23032… │ │
│ │                         │   │                                                                │ │
│ │                         PosixPath('KV19-4396-neg-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Dia… │ │
│ │                         │   ),                                                               │ │
│ │                         │   (                                                                │ │
│ │                         │   │                                                                │ │
│ │                         'KV23-5721-moc-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_23032… │ │
│ │                         │   │                                                                │ │
│ │                         PosixPath('KV23-5721-moc-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Dia… │ │
│ │                         │   ),                                                               │ │
│ │                         │   (                                                                │ │
│ │                         │   │                                                                │ │
│ │                         'KV23-5721-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.di… │ │
│ │                         │   │                                                                │ │
│ │                         PosixPath('KV23-5721-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond… │ │
│ │                         │   )                                                                │ │
│ │                         ]                                                                    │ │
│ │          handling_app = <taxpasta.application.sample_handling_application.SampleHandlingApp… │ │
│ │                         object at 0x7f9e7a123790>                                            │ │
│ │         ignore_errors = True                                                                 │ │
│ │                  name = 'KV23-5721-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.di… │ │
│ │                output = PosixPath('diamond_Diamond_230321.tsv')                              │ │
│ │         output_format = None                                                                 │ │
│ │               profile = PosixPath('KV23-5721-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond… │ │
│ │              profiler = <SupportedProfiler.diamond: 'diamond'>                               │ │
│ │              profiles = [                                                                    │ │
│ │                         │                                                                    │ │
│ │                         PosixPath('KV23-5721-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond… │ │
│ │                         │                                                                    │ │
│ │                         PosixPath('KV19-4396-moc-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Dia… │ │
│ │                         │                                                                    │ │
│ │                         PosixPath('KV19-4396-neg-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Dia… │ │
│ │                         │                                                                    │ │
│ │                         PosixPath('KV19-4396-moc-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Dia… │ │
│ │                         │                                                                    │ │
│ │                         PosixPath('KV23-5721-moc-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Dia… │ │
│ │                         │                                                                    │ │
│ │                         PosixPath('KV20-1130-posEV-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_D… │ │
│ │                         │                                                                    │ │
│ │                         PosixPath('KV19-4396-neg-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Dia… │ │
│ │                         │                                                                    │ │
│ │                         PosixPath('KV23-5721-moc-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Dia… │ │
│ │                         │                                                                    │ │
│ │                         PosixPath('KV23-5721-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond… │ │
│ │                         ]                                                                    │ │
│ │                result = │    taxonomy_id  ...                                                │ │
│ │                         KV23-5721-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.dia… │ │
│ │                         0              0  ...                                                │ │
│ │                         247959                                                               │ │
│ │                         1              2  ...                                                │ │
│ │                         98062                                                                │ │
│ │                         2           1236  ...                                                │ │
│ │                         1290                                                                 │ │
│ │                         3        2987757  ...                                                │ │
│ │                         36                                                                   │ │
│ │                         4            562  ...                                                │ │
│ │                         1783                                                                 │ │
│ │                         ...          ...  ...                                                │ │
│ │                         ...                                                                  │ │
│ │                         2649     1079859  ...                                                │ │
│ │                         1                                                                    │ │
│ │                         2650      586132  ...                                                │ │
│ │                         1                                                                    │ │
│ │                         2651      717646  ...                                                │ │
│ │                         1                                                                    │ │
│ │                         2652     1462615  ...                                                │ │
│ │                         1                                                                    │ │
│ │                         2653      235443  ...                                                │ │
│ │                         1                                                                    │ │
│ │                                                                                              │ │
│ │                         [2654 rows x 10 columns]                                             │ │
│ │          sample_sheet = None                                                                 │ │
│ │               samples = [                                                                    │ │
│ │                         │   Sample(                                                          │ │
│ │                         │   │                                                                │ │
│ │                         name='KV23-5721-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_2303… │ │
│ │                         │   │   profile=    taxonomy_id   count                              │ │
│ │                         0             0  582432                                              │ │
│ │                         1             2  100111                                              │ │
│ │                         2          1236    9627                                              │ │
│ │                         3       2987757     311                                              │ │
│ │                         4           562    4961                                              │ │
│ │                         ..          ...     ...                                              │ │
│ │                         623         820       1                                              │ │
│ │                         624      106654       1                                              │ │
│ │                         625     2793816       1                                              │ │
│ │                         626      519051       1                                              │ │
│ │                         627       61645       2                                              │ │
│ │                                                                                              │ │
│ │                         [628 rows x 2 columns]                                               │ │
│ │                         │   ),                                                               │ │
│ │                         │   Sample(                                                          │ │
│ │                         │   │                                                                │ │
│ │                         name='KV19-4396-moc-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_… │ │
│ │                         │   │   profile=    taxonomy_id    count                             │ │
│ │                         0             0  4930069                                             │ │
│ │                         1         91061   111846                                             │ │
│ │                         2          1318    66094                                             │ │
│ │                         3          1385    13141                                             │ │
│ │                         4        716545   273649                                             │ │
│ │                         ..          ...      ...                                             │ │
│ │                         506     2762612        2                                             │ │
│ │                         507     1314678        1                                             │ │
│ │                         508     1552123        2                                             │ │
│ │                         509        1282        1                                             │ │
│ │                         510     2817997        1                                             │ │
│ │                                                                                              │ │
│ │                         [511 rows x 2 columns]                                               │ │
│ │                         │   ),                                                               │ │
│ │                         │   Sample(                                                          │ │
│ │                         │   │                                                                │ │
│ │                         name='KV19-4396-neg-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_… │ │
│ │                         │   │   profile=    taxonomy_id   count                              │ │
│ │                         0          5204    9494                                              │ │
│ │                         1             0  295842                                              │ │
│ │                         2          1224    6402                                              │ │
│ │                         3        451864   16479                                              │ │
│ │                         4             2   19330                                              │ │
│ │                         ..          ...     ...                                              │ │
│ │                         929     2763074       1                                              │ │
│ │                         930      647910       2                                              │ │
│ │                         931     2722702       2                                              │ │
│ │                         932      238749       1                                              │ │
│ │                         933      461281       2                                              │ │
│ │                                                                                              │ │
│ │                         [934 rows x 2 columns]                                               │ │
│ │                         │   ),                                                               │ │
│ │                         │   Sample(                                                          │ │
│ │                         │   │                                                                │ │
│ │                         name='KV19-4396-moc-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_… │ │
│ │                         │   │   profile=    taxonomy_id    count                             │ │
│ │                         0             0   835571                                             │ │
│ │                         1          1224   674880                                             │ │
│ │                         2           286  2829440                                             │ │
│ │                         3          1236  2481652                                             │ │
│ │                         4             2  1532407                                             │ │
│ │                         ..          ...      ...                                             │ │
│ │                         961     2480627        2                                             │ │
│ │                         962     2816356        2                                             │ │
│ │                         963     2494702        1                                             │ │
│ │                         964        1054        2                                             │ │
│ │                         965     1571224        2                                             │ │
│ │                                                                                              │ │
│ │                         [966 rows x 2 columns]                                               │ │
│ │                         │   ),                                                               │ │
│ │                         │   Sample(                                                          │ │
│ │                         │   │                                                                │ │
│ │                         name='KV23-5721-moc-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_… │ │
│ │                         │   │   profile=    taxonomy_id   count                              │ │
│ │                         0           196      60                                              │ │
│ │                         1             0  855172                                              │ │
│ │                         2             2  162737                                              │ │
│ │                         3           286   37487                                              │ │
│ │                         4          1236   46419                                              │ │
│ │                         ..          ...     ...                                              │ │
│ │                         845     1923970       1                                              │ │
│ │                         846     1581058       1                                              │ │
│ │                         847      990412       1                                              │ │
│ │                         848     2723299       2                                              │ │
│ │                         849       11788       2                                              │ │
│ │                                                                                              │ │
│ │                         [850 rows x 2 columns]                                               │ │
│ │                         │   ),                                                               │ │
│ │                         │   Sample(                                                          │ │
│ │                         │   │                                                                │ │
│ │                         name='KV20-1130-posEV-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamon… │ │
│ │                         │   │   profile=    taxonomy_id   count                              │ │
│ │                         0             0  689250                                              │ │
│ │                         1       2498453    3590                                              │ │
│ │                         2         33883    1979                                              │ │
│ │                         3       2883480     498                                              │ │
│ │                         4             2   34499                                              │ │
│ │                         ..          ...     ...                                              │ │
│ │                         778     2785789       1                                              │ │
│ │                         779     2795110       1                                              │ │
│ │                         780     2022783       2                                              │ │
│ │                         781      201174       1                                              │ │
│ │                         782     1535325       1                                              │ │
│ │                                                                                              │ │
│ │                         [783 rows x 2 columns]                                               │ │
│ │                         │   ),                                                               │ │
│ │                         │   Sample(                                                          │ │
│ │                         │   │                                                                │ │
│ │                         name='KV19-4396-neg-DNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_… │ │
│ │                         │   │   profile=    taxonomy_id  count                               │ │
│ │                         0             0   9301                                               │ │
│ │                         1             2   1126                                               │ │
│ │                         2        112252      1                                               │ │
│ │                         3          1286      4                                               │ │
│ │                         4        131567    176                                               │ │
│ │                         ..          ...    ...                                               │ │
│ │                         105        1308      1                                               │ │
│ │                         106      599839      1                                               │ │
│ │                         107     2841671      1                                               │ │
│ │                         108        1717      1                                               │ │
│ │                         109       29430      2                                               │ │
│ │                                                                                              │ │
│ │                         [110 rows x 2 columns]                                               │ │
│ │                         │   ),                                                               │ │
│ │                         │   Sample(                                                          │ │
│ │                         │   │                                                                │ │
│ │                         name='KV23-5721-moc-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_… │ │
│ │                         │   │   profile=    taxonomy_id   count                              │ │
│ │                         0        559292    2413                                              │ │
│ │                         1        683960     713                                              │ │
│ │                         2             0  415441                                              │ │
│ │                         3        131567    5971                                              │ │
│ │                         4             2   39427                                              │ │
│ │                         ..          ...     ...                                              │ │
│ │                         625     1544694       1                                              │ │
│ │                         626     2497436       2                                              │ │
│ │                         627     2726947       1                                              │ │
│ │                         628       12916       1                                              │ │
│ │                         629       80878       1                                              │ │
│ │                                                                                              │ │
│ │                         [630 rows x 2 columns]                                               │ │
│ │                         │   ),                                                               │ │
│ │                         │   Sample(                                                          │ │
│ │                         │   │                                                                │ │
│ │                         name='KV23-5721-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_2303… │ │
│ │                         │   │   profile=    taxonomy_id   count                              │ │
│ │                         0             2   98062                                              │ │
│ │                         1             0  247959                                              │ │
│ │                         2          4751   17173                                              │ │
│ │                         3           470    3506                                              │ │
│ │                         4        131567    6405                                              │ │
│ │                         ..          ...     ...                                              │ │
│ │                         875      717646       1                                              │ │
│ │                         876     1462615       1                                              │ │
│ │                         877       50290       1                                              │ │
│ │                         878      721885       1                                              │ │
│ │                         879      235443       1                                              │ │
│ │                                                                                              │ │
│ │                         [880 rows x 2 columns]                                               │ │
│ │                         │   )                                                                │ │
│ │                         ]                                                                    │ │
│ │    samplesheet_format = None                                                                 │ │
│ │          summarise_at = None                                                                 │ │
│ │              taxonomy = PosixPath('/medstore/databases/taxprofiler/databases/taxpasta_taxon… │ │
│ │      taxonomy_service = <taxpasta.infrastructure.domain.service.taxopy_taxonomy_service.Tax… │ │
│ │                         object at 0x7f9e7a14a990>                                            │ │
│ │ TaxopyTaxonomyService = <class                                                               │ │
│ │                         'taxpasta.infrastructure.domain.service.taxopy_taxonomy_service.Tax… │ │
│ │   valid_output_format = <WideObservationTableFileFormat.TSV: 'TSV'>                          │ │
│ │           wide_format = True                                                                 │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /home/xabras/.conda/envs/TaxPasta/lib/python3.11/site-packages/taxpasta/application/add_tax_info │
│ _command.py:50 in execute                                                                        │
│                                                                                                  │
│    47 │   │   result = sample                                                                    │
│    48 │   │   if self.add_rank_lineage:                                                          │
│    49 │   │   │   result = Sample(                                                               │
│ ❱  50 │   │   │   │   name=result.name,                                                          │
│    51 │   │   │   │   profile=self.taxonomy_service.add_rank_lineage(result.profile),            │
│    52 │   │   │   )                                                                              │
│    53 │   │   if self.add_id_lineage:                                                            │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ result = │    taxonomy_id  ...                                                               │ │
│ │          KV23-5721-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.diamond             │ │
│ │          0              0  ...                                             247959            │ │
│ │          1              2  ...                                              98062            │ │
│ │          2           1236  ...                                               1290            │ │
│ │          3        2987757  ...                                                 36            │ │
│ │          4            562  ...                                               1783            │ │
│ │          ...          ...  ...                                                ...            │ │
│ │          2649     1079859  ...                                                  1            │ │
│ │          2650      586132  ...                                                  1            │ │
│ │          2651      717646  ...                                                  1            │ │
│ │          2652     1462615  ...                                                  1            │ │
│ │          2653      235443  ...                                                  1            │ │
│ │                                                                                              │ │
│ │          [2654 rows x 10 columns]                                                            │ │
│ │ sample = │    taxonomy_id  ...                                                               │ │
│ │          KV23-5721-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.diamond             │ │
│ │          0              0  ...                                             247959            │ │
│ │          1              2  ...                                              98062            │ │
│ │          2           1236  ...                                               1290            │ │
│ │          3        2987757  ...                                                 36            │ │
│ │          4            562  ...                                               1783            │ │
│ │          ...          ...  ...                                                ...            │ │
│ │          2649     1079859  ...                                                  1            │ │
│ │          2650      586132  ...                                                  1            │ │
│ │          2651      717646  ...                                                  1            │ │
│ │          2652     1462615  ...                                                  1            │ │
│ │          2653      235443  ...                                                  1            │ │
│ │                                                                                              │ │
│ │          [2654 rows x 10 columns]                                                            │ │
│ │   self = AddTaxInfoCommand(                                                                  │ │
│ │          │                                                                                   │ │
│ │          taxonomy_service=<taxpasta.infrastructure.domain.service.taxopy_taxonomy_service.T… │ │
│ │          object at 0x7f9e7a14a990>,                                                          │ │
│ │          │   summarise_at=None,                                                              │ │
│ │          │   add_name=True,                                                                  │ │
│ │          │   add_rank=True,                                                                  │ │
│ │          │   add_lineage=True,                                                               │ │
│ │          │   add_id_lineage=True,                                                            │ │
│ │          │   add_rank_lineage=True                                                           │ │
│ │          )                                                                                   │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /home/xabras/.conda/envs/TaxPasta/lib/python3.11/site-packages/pandas/core/generic.py:5902 in    │
│ __getattr__                                                                                      │
│                                                                                                  │
│    5899 │   │   │   and self._info_axis._can_hold_identifiers_and_holds_name(name)               │
│    5900 │   │   ):                                                                               │
│    5901 │   │   │   return self[name]                                                            │
│ ❱  5902 │   │   return object.__getattribute__(self, name)                                       │
│    5903 │                                                                                        │
│    5904 │   def __setattr__(self, name: str, value) -> None:                                     │
│    5905 │   │   """                                                                              │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ name = 'name'                                                                                │ │
│ │ self = │    taxonomy_id  ...                                                                 │ │
│ │        KV23-5721-RNA_pe_230627_NB501037_0884_AHK5LVAFX5_Diamond_230321.diamond               │ │
│ │        0              0  ...                                             247959              │ │
│ │        1              2  ...                                              98062              │ │
│ │        2           1236  ...                                               1290              │ │
│ │        3        2987757  ...                                                 36              │ │
│ │        4            562  ...                                               1783              │ │
│ │        ...          ...  ...                                                ...              │ │
│ │        2649     1079859  ...                                                  1              │ │
│ │        2650      586132  ...                                                  1              │ │
│ │        2651      717646  ...                                                  1              │ │
│ │        2652     1462615  ...                                                  1              │ │
│ │        2653      235443  ...                                                  1              │ │
│ │                                                                                              │ │
│ │        [2654 rows x 10 columns]                                                              │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'DataFrame' object has no attribute 'name'

```


### Environment

<details>

### Package Information

| Package  | Version |
|:---------|--------:|
| taxpasta |   0.6.0 |

### Dependency Information

|           Package            |   Version   |
|:-----------------------------|------------:|
| bash-kernel                  | **missing** |
| biom-format                  |      2.1.14 |
| depinfo~                     | **missing** |
| jupyter                      | **missing** |
| mkdocs-awesome-pages-plugin~ | **missing** |
| mkdocs-exclude~              | **missing** |
| mkdocs-material~             | **missing** |
| mkdocstrings[python]~        | **missing** |
| numpy~                       | **missing** |
| odfpy                        | **missing** |
| openpyxl                     | **missing** |
| pandas~                      | **missing** |
| pandera~                     | **missing** |
| pre-commit                   | **missing** |
| pyarrow                      |      11.0.0 |
| rich                         |      12.6.0 |
| tabulate~                    | **missing** |
| taxopy~                      | **missing** |
| tox~                         | **missing** |
| typer~                       | **missing** |

### Build Tools Information

|  Package   | Version |
|:-----------|--------:|
| pip        |  23.1.2 |
| setuptools |  67.7.2 |
| wheel      |  0.40.0 |

### Platform Information

|         |                                     |
|:--------|------------------------------------:|
| Linux   | 4.18.0-425.13.1.el8_7.x86_64-x86_64 |
| CPython |                              3.11.3 |


</details>


### Anything else?

_No response_

Discussion:
codecov-commenter: ## [Codecov](https://app.codecov.io/gh/taxprofiler/taxpasta/pull/139?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
All modified lines are covered by tests :white_check_mark:
> Comparison is base [(`9931588`)](https://app.codecov.io/gh/taxprofiler/taxpasta/commit/99315886137a5b522bf6e731698c238606853e86?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) 88.19% compared to head [(`2c51c10`)](https://app.codecov.io/gh/taxprofiler/taxpasta/pull/139?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) 89.28%.

> :exclamation: Current head 2c51c10 differs from pull request most recent head 8464831. Consider uploading reports for the commit 8464831 to get more accurate results

:exclamation: Your organization needs to install the [Codecov GitHub app](https://github.com/apps/codecov/installations/select_target) to enable full functionality.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##              dev     #139      +/-   ##
==========================================
+ Coverage   88.19%   89.28%   +1.09%     
==========================================
  Files         114      114              
  Lines        1762     1764       +2     
  Branches      303      130     -173     
==========================================
+ Hits         1554     1575      +21     
+ Misses        176      158      -18     
+ Partials       32       31       -1     
```


| [Files](https://app.codecov.io/gh/taxprofiler/taxpasta/pull/139?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [src/taxpasta/application/add\_tax\_info\_command.py](https://app.codecov.io/gh/taxprofiler/taxpasta/pull/139?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3RheHBhc3RhL2FwcGxpY2F0aW9uL2FkZF90YXhfaW5mb19jb21tYW5kLnB5) | `73.33% <100.00%> (+31.47%)` | :arrow_up: |
| [src/taxpasta/infrastructure/cli/standardise.py](https://app.codecov.io/gh/taxprofiler/taxpasta/pull/139?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-c3JjL3RheHBhc3RhL2luZnJhc3RydWN0dXJlL2NsaS9zdGFuZGFyZGlzZS5weQ==) | `47.88% <100.00%> (ø)` | |

... and [1 file with indirect coverage changes](https://app.codecov.io/gh/taxprofiler/taxpasta/pull/139/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/taxprofiler/taxpasta/pull/139?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).

Midnighter: > For the tests does it make sense to include a test of a generating more realalistic table and with multiple of the columns?

I should really add this to the CLI tests. Then we'd test the command options and with more realistic tables.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1076350..cc1efe3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Fixed
+
+-   Repaired the logic for adding taxonomic information to the output table (#139).
+
 ## [0.6.0] - (2023-09-10)
 
 ### Added
diff --git a/src/taxpasta/application/add_tax_info_command.py b/src/taxpasta/application/add_tax_info_command.py
index 8aac2a4..79f9ba3 100644
--- a/src/taxpasta/application/add_tax_info_command.py
+++ b/src/taxpasta/application/add_tax_info_command.py
@@ -20,15 +20,29 @@
 
 
 from dataclasses import dataclass
-from typing import Optional
+from typing import Optional, TypeVar
 
-from taxpasta.domain.model import Sample
+from pandera.typing import DataFrame
+
+from taxpasta.domain.model import (
+    StandardProfile,
+    TidyObservationTable,
+    WideObservationTable,
+)
 from taxpasta.domain.service import TaxonomyService
 
 
+Table = TypeVar(
+    "Table",
+    DataFrame[TidyObservationTable],
+    DataFrame[WideObservationTable],
+    DataFrame[StandardProfile],
+)
+
+
 @dataclass(frozen=True)
 class AddTaxInfoCommand:
-    """Define a command object for adding taxonomy information."""
+    """Define the command object for adding taxonomy information."""
 
     taxonomy_service: Optional[TaxonomyService] = None
     summarise_at: Optional[str] = None
@@ -38,36 +52,23 @@ class AddTaxInfoCommand:
     add_id_lineage: bool = False
     add_rank_lineage: bool = False
 
-    def execute(self, sample: Sample) -> Sample:
+    def execute(self, table: Table) -> Table:
         """Execute the command to add taxonomy information."""
         if self.taxonomy_service is None:
-            return sample
+            return table
         # The order of the following conditions is chosen specifically to yield a
         # pleasant final output format.
-        result = sample
+        result = table
         if self.add_rank_lineage:
-            result = Sample(
-                name=result.name,
-                profile=self.taxonomy_service.add_rank_lineage(result.profile),
-            )
+            result = self.taxonomy_service.add_rank_lineage(result)
         if self.add_id_lineage:
-            result = Sample(
-                name=result.name,
-                profile=self.taxonomy_service.add_identifier_lineage(result.profile),
-            )
+            result = self.taxonomy_service.add_identifier_lineage(result)
         if self.add_lineage:
-            result = Sample(
-                name=result.name,
-                profile=self.taxonomy_service.add_name_lineage(result.profile),
-            )
+            result = self.taxonomy_service.add_name_lineage(result)
         if self.add_rank:
-            result = Sample(
-                name=result.name, profile=self.taxonomy_service.add_rank(result.profile)
-            )
+            result = self.taxonomy_service.add_rank(result)
         if self.add_name:
-            result = Sample(
-                name=result.name, profile=self.taxonomy_service.add_name(result.profile)
-            )
+            result = self.taxonomy_service.add_name(result)
         return result
 
     def __post_init__(self) -> None:
diff --git a/src/taxpasta/infrastructure/cli/standardise.py b/src/taxpasta/infrastructure/cli/standardise.py
index c84cf29..30fbec7 100644
--- a/src/taxpasta/infrastructure/cli/standardise.py
+++ b/src/taxpasta/infrastructure/cli/standardise.py
@@ -226,12 +226,12 @@ def standardise(
             logger.critical(str(error))
             raise typer.Exit(code=1)
 
-    result = tax_info_command.execute(sample)
+    result = tax_info_command.execute(sample.profile)
 
     logger.info("Write result to '%s'.", str(output))
     writer = ApplicationServiceRegistry.standard_profile_writer(valid_output_format)
     try:
-        writer.write(result.profile, output)
+        writer.write(result, output)
     except OSError as error:
         logger.critical("Failed to write the output result.")
         logger.critical(str(error))


Test patch:
diff --git a/tests/integration/test_add_tax_info.py b/tests/integration/test_add_tax_info.py
new file mode 100644
index 0000000..e52c90e
--- /dev/null
+++ b/tests/integration/test_add_tax_info.py
@@ -0,0 +1,88 @@
+# Copyright (c) 2023 Moritz E. Beber
+# Copyright (c) 2023 Maxime Borry
+# Copyright (c) 2023 James A. Fellows Yates
+# Copyright (c) 2023 Sofia Stamouli.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+"""Test the command object for adding taxonomy information."""
+
+
+from pathlib import Path
+
+import pandas as pd
+import pytest
+from pandera.typing import DataFrame
+
+from taxpasta.application import AddTaxInfoCommand
+from taxpasta.domain.model import StandardProfile
+from taxpasta.infrastructure.domain.service.taxopy_taxonomy_service import (
+    TaxopyTaxonomyService,
+)
+
+
+@pytest.fixture(scope="module")
+def tax_service(taxonomy_data_dir: Path) -> TaxopyTaxonomyService:
+    """Provide an instance of the taxopy taxonomy service."""
+    return TaxopyTaxonomyService.from_taxdump(taxonomy_data_dir)
+
+
+@pytest.fixture()
+def profile() -> DataFrame[StandardProfile]:
+    """Provide a generic profile to modify."""
+    return pd.DataFrame({"taxonomy_id": [1, 476817098, 609216830], "count": [1, 2, 3]})
+
+
+def test_add_name(tax_service: TaxopyTaxonomyService, profile: pd.DataFrame):
+    """Test that a column with taxon names is added."""
+    command = AddTaxInfoCommand(add_name=True, taxonomy_service=tax_service)
+    result = command.execute(profile)
+    assert "name" in result.columns
+    assert result["name"].tolist() == ["root", "Eukaryota", "Bacteria"]
+
+
+def test_add_rank(tax_service: TaxopyTaxonomyService, profile: pd.DataFrame):
+    """Test that a column with taxon ranks is added."""
+    command = AddTaxInfoCommand(add_rank=True, taxonomy_service=tax_service)
+    result = command.execute(profile)
+    assert "rank" in result.columns
+    assert result["rank"].tolist() == ["no rank", "superkingdom", "superkingdom"]
+
+
+def test_add_lineage(tax_service: TaxopyTaxonomyService, profile: pd.DataFrame):
+    """Test that a column with taxon lineages is added."""
+    command = AddTaxInfoCommand(add_lineage=True, taxonomy_service=tax_service)
+    result = command.execute(profile)
+    assert "lineage" in result.columns
+    assert result["lineage"].tolist() == [None, "Eukaryota", "Bacteria"]
+
+
+def test_add_id_lineage(tax_service: TaxopyTaxonomyService, profile: pd.DataFrame):
+    """Test that a column with taxon identifier lineages is added."""
+    command = AddTaxInfoCommand(add_id_lineage=True, taxonomy_service=tax_service)
+    result = command.execute(profile)
+    assert "id_lineage" in result.columns
+    assert result["id_lineage"].tolist() == [None, "476817098", "609216830"]
+
+
+def test_add_rank_lineage(tax_service: TaxopyTaxonomyService, profile: pd.DataFrame):
+    """Test that a column with taxon rank lineages is added."""
+    command = AddTaxInfoCommand(add_rank_lineage=True, taxonomy_service=tax_service)
+    result = command.execute(profile)
+    assert "rank_lineage" in result.columns
+    assert result["rank_lineage"].tolist() == [
+        None,
+        "superkingdom",
+        "superkingdom",
+    ]