Repository: sdv-dev/SDV

Issue:
Sampling with HMA Synthesizer generates many `SingleTableMetadata` deprecation warnings
### Environment Details

* SDV version: 1.17.1 (latest)

### Error Description

When sampling using an HMA Synthesizer object that was instantiated using a MultiTableMetadata object, the SingleTableMetadata deprecation warning is repeatedly logged:

<img width="1568" alt="Screenshot 2024-11-12 at 4 13 44 PM" src="https://github.com/user-attachments/assets/ebd3b169-4314-41e1-b157-10e075354519">

This warning isn't very helpful (as it describes the SingleTableMetadata object) and repeats many times (it loosely seems like a larger volume of data generates more warnings). The user is already shown an accurate warning during synthesizer instantiation:

```
/usr/local/lib/python3.10/dist-packages/sdv/multi_table/base.py:110: FutureWarning: The 'MultiTableMetadata' is deprecated. Please use the new 'Metadata' class for synthesizers.
  warnings.warn(DEPRECATION_MSG, FutureWarning)
```

### Steps to reproduce

[Internal Colab Notebook to reproduce](https://colab.research.google.com/drive/1nn32sXxCqwSYjAY3-4lv17Q01Q3QWq_v?usp=sharing)

```
from sdv.datasets.demo import download_demo
from sdv.metadata import MultiTableMetadata
from sdv.multi_table import HMASynthesizer

data, metadata = download_demo(
    modality='multi_table',
    dataset_name='fake_hotels'
)

guests_table = data['guests']
hotels_table = data['hotels']

multi_metadata = MultiTableMetadata()
multi_metadata.detect_from_dataframes(data)

synthesizer = HMASynthesizer(multi_metadata)
synthesizer.fit(real_data)
synthetic_data = synthesizer.sample()
```

Hints from issue comments:

Solution patch:
diff --git a/sdv/multi_table/hma.py b/sdv/multi_table/hma.py
index 6989f691..f93967ad 100644
--- a/sdv/multi_table/hma.py
+++ b/sdv/multi_table/hma.py
@@ -1,6 +1,7 @@
 """Hierarchical Modeling Algorithms."""
 
 import logging
+import warnings
 from collections import defaultdict
 from copy import deepcopy
 
@@ -552,7 +553,12 @@ class HMASynthesizer(BaseHierarchicalSampler, BaseMultiTableSynthesizer):
             parameters = self._extract_parameters(parent_row, child_name, foreign_key)
             default_parameters = getattr(self, '_default_parameters', {}).get(child_name, {})
             table_meta = self.metadata.get_table_metadata(child_name)
-            synthesizer = self._synthesizer(table_meta, **self._table_parameters[child_name])
+            with warnings.catch_warnings():
+                warnings.filterwarnings(
+                    'ignore', message=".*The 'SingleTableMetadata' is deprecated.*"
+                )
+                synthesizer = self._synthesizer(table_meta, **self._table_parameters[child_name])
+
             synthesizer._set_parameters(parameters, default_parameters)
         else:
             synthesizer = self._null_child_synthesizers[f'__{child_name}__{foreign_key}']


Test patch:
diff --git a/tests/integration/multi_table/test_hma.py b/tests/integration/multi_table/test_hma.py
index 9e705811..2539ff98 100644
--- a/tests/integration/multi_table/test_hma.py
+++ b/tests/integration/multi_table/test_hma.py
@@ -19,6 +19,7 @@ from sdv.datasets.demo import download_demo
 from sdv.datasets.local import load_csvs
 from sdv.errors import SamplingError, SynthesizerInputError, VersionError
 from sdv.evaluation.multi_table import evaluate_quality, get_column_pair_plot, get_column_plot
+from sdv.metadata import MultiTableMetadata
 from sdv.metadata.metadata import Metadata
 from sdv.multi_table import HMASynthesizer
 from tests.integration.single_table.custom_constraints import MyConstraint
@@ -2637,3 +2638,20 @@ def test_column_order():
     assert table_1_column != list(data['table_1'].columns)
     assert table_1_column == ['col_1', 'col_2', 'col_3']
     assert list(synthetic_data['table_2'].columns) == ['col_A', 'col_B', 'col_C']
+
+
+def test_no_deprecation_warning_single_table_metadata_sampling():
+    """Test that no single-table metadata deprecation warning raises with `MultiTableMetadata`."""
+    # Setup
+    data, _ = download_demo(modality='multi_table', dataset_name='fake_hotels')
+    multi_metadata = MultiTableMetadata()
+    multi_metadata.detect_from_dataframes(data)
+    synthesizer = HMASynthesizer(multi_metadata)
+    synthesizer.fit(data)
+
+    # Run
+    with warnings.catch_warnings(record=True) as captured_warnings:
+        synthesizer.sample()
+
+    # Assert
+    assert len(captured_warnings) == 0