Repository: sdv-dev/RDT

Issue:
Rename `IDGenerator` transformer to `IndexGenerator`
### Problem Description
Currently the [IDGenerator transformer](https://docs.sdv.dev/rdt/transformers-glossary/id/idgenerator) is used to create an ID column from scratch when it represents an ordered index (`0, 1, 2, 3, ...`) with optional prefixes and suffixes (eg. `id_0, id_1, id_2, ...`.

While this transformer is useful for certain types of datasets, the name **IDGenerator** is not very descriptive of what it's doing. There can be many different ways to generate IDs (which we eventually plan to add); creating ordered indices is just one such way.

### Expected behavior
Rename the `IDGenerator` to `IndexGenerator` to make it clear that this transformer is specifically for ID columns that are indices.

Note that RDT transformers _should_ be backwards compatible. So if someone is still using `IDGenerator` in their code, we should throw a `FutureWarning` explaining that it has been deprecated. However, the code can continue to work, using the `IndexGenerator` under-the-hood instead.

```python
>>> from rdt.transformers.id import IDGenerator
>>> transformer = IDGenerator(prefix='id_', starting_value=0)
FutureWarning: The 'IDGenerator' has been renamed to 'IndexGenerator'.
```

Discussion:

Solution patch:
diff --git a/rdt/transformers/__init__.py b/rdt/transformers/__init__.py
index 1381bfe..75a20ba 100644
--- a/rdt/transformers/__init__.py
+++ b/rdt/transformers/__init__.py
@@ -22,7 +22,7 @@ from rdt.transformers.datetime import (
     OptimizedTimestampEncoder,
     UnixTimestampEncoder,
 )
-from rdt.transformers.id import IDGenerator, RegexGenerator
+from rdt.transformers.id import IDGenerator, IndexGenerator, RegexGenerator
 from rdt.transformers.null import NullTransformer
 from rdt.transformers.numerical import (
     ClusterBasedNormalizer,
@@ -57,6 +57,7 @@ __all__ = [
     'AnonymizedFaker',
     'PseudoAnonymizedFaker',
     'IDGenerator',
+    'IndexGenerator',
     'get_transformer_name',
     'get_transformer_class',
     'get_transformers_by_type',
diff --git a/rdt/transformers/id.py b/rdt/transformers/id.py
index e1eaedc..59b622f 100644
--- a/rdt/transformers/id.py
+++ b/rdt/transformers/id.py
@@ -12,7 +12,7 @@ from rdt.transformers.utils import strings_from_regex
 LOGGER = logging.getLogger(__name__)
 
 
-class IDGenerator(BaseTransformer):
+class IndexGenerator(BaseTransformer):
     """Generate an ID column.
 
     This transformer generates an ID column based on a given prefix, starting value and suffix.
@@ -72,6 +72,21 @@ class IDGenerator(BaseTransformer):
         return pd.Series(values)
 
 
+class IDGenerator(IndexGenerator):
+    """Deprecated class name for ``IndexGenerator``.
+
+    Class to ensure backwards compatibility with previous versions of RDT.
+    """
+
+    def __init__(self, prefix=None, starting_value=0, suffix=None):
+        warnings.warn(
+            "The 'IDGenerator' has been renamed to 'IndexGenerator'. Please update the"
+            'name to ensure compatibility with future versions of RDT.',
+            FutureWarning,
+        )
+        super().__init__(prefix, starting_value, suffix)
+
+
 class RegexGenerator(BaseTransformer):
     """RegexGenerator transformer.
 


Test patch:
diff --git a/tests/integration/transformers/test_id.py b/tests/integration/transformers/test_id.py
index eaa9067..cfa148c 100644
--- a/tests/integration/transformers/test_id.py
+++ b/tests/integration/transformers/test_id.py
@@ -4,12 +4,12 @@ import numpy as np
 import pandas as pd
 
 from rdt import HyperTransformer, get_demo
-from rdt.transformers.id import IDGenerator, RegexGenerator
+from rdt.transformers.id import IndexGenerator, RegexGenerator
 
 
-class TestIDGenerator:
+class TestIndexGenerator:
     def test_end_to_end(self):
-        """End to end test of the ``IDGenerator``."""
+        """End to end test of the ``IndexGenerator``."""
         # Setup
         data = pd.DataFrame({
             'id': [1, 2, 3, 4, 5],
@@ -17,7 +17,7 @@ class TestIDGenerator:
         })
 
         # Run
-        transformer = IDGenerator(prefix='id_', starting_value=100, suffix='_X')
+        transformer = IndexGenerator(prefix='id_', starting_value=100, suffix='_X')
         transformed = transformer.fit_transform(data, 'id')
         reverse_transform = transformer.reverse_transform(transformed)
         reverse_transform_2 = transformer.reverse_transform(transformed)
diff --git a/tests/unit/transformers/test_id.py b/tests/unit/transformers/test_id.py
index b3f8d09..298f30f 100644
--- a/tests/unit/transformers/test_id.py
+++ b/tests/unit/transformers/test_id.py
@@ -1,5 +1,6 @@
 """Test for ID transformers."""
 
+import re
 from string import ascii_uppercase
 from unittest.mock import Mock, patch
 
@@ -7,7 +8,7 @@ import numpy as np
 import pandas as pd
 import pytest
 
-from rdt.transformers.id import IDGenerator, RegexGenerator
+from rdt.transformers.id import IDGenerator, IndexGenerator, RegexGenerator
 
 
 class AsciiGenerator:
@@ -30,11 +31,11 @@ class AsciiGenerator:
         return char
 
 
-class TestIDGenerator:
+class TestIndexGenerator:
     def test___init__default(self):
         """Test the ``__init__`` method."""
         # Run
-        transformer = IDGenerator()
+        transformer = IndexGenerator()
 
         # Assert
         assert transformer.prefix is None
@@ -46,10 +47,10 @@ class TestIDGenerator:
     def test___init__with_parameters(self):
         """Test the ``__init__`` method with paremeters."""
         # Run
-        transformer_prefix = IDGenerator(prefix='prefix_')
-        transformer_suffix = IDGenerator(suffix='_suffix')
-        transformer_starting_value = IDGenerator(starting_value=10)
-        transformer_all = IDGenerator(prefix='prefix_', starting_value=10, suffix='_suffix')
+        transformer_prefix = IndexGenerator(prefix='prefix_')
+        transformer_suffix = IndexGenerator(suffix='_suffix')
+        transformer_starting_value = IndexGenerator(starting_value=10)
+        transformer_all = IndexGenerator(prefix='prefix_', starting_value=10, suffix='_suffix')
 
         # Assert
         assert transformer_prefix.prefix == 'prefix_'
@@ -79,7 +80,7 @@ class TestIDGenerator:
     def test_reset_randomization(self):
         """Test the ``reset_randomization`` method."""
         # Setup
-        transformer = IDGenerator()
+        transformer = IndexGenerator()
         transformer._counter = 10
 
         # Run
@@ -91,7 +92,7 @@ class TestIDGenerator:
     def test__fit(self):
         """Test the ``_fit`` method."""
         # Setup
-        transformer = IDGenerator()
+        transformer = IndexGenerator()
 
         # Run
         transformer._fit(None)
@@ -102,7 +103,7 @@ class TestIDGenerator:
     def test__transform(self):
         """Test the ``_transform`` method."""
         # Setup
-        transformer = IDGenerator()
+        transformer = IndexGenerator()
 
         # Run
         result = transformer._transform(None)
@@ -113,7 +114,7 @@ class TestIDGenerator:
     def test__reverse_transform(self):
         """Test the ``_reverse_transform`` method."""
         # Setup
-        transformer = IDGenerator()
+        transformer = IndexGenerator()
         transformer._counter = 10
 
         # Run
@@ -127,7 +128,7 @@ class TestIDGenerator:
     def test__reverse_transform_with_everything(self):
         """Test the ``_reverse_transform`` method with all parameters."""
         # Setup
-        transformer = IDGenerator(prefix='prefix_', starting_value=100, suffix='_suffix')
+        transformer = IndexGenerator(prefix='prefix_', starting_value=100, suffix='_suffix')
 
         # Run
         result = transformer._reverse_transform(np.array([1, 2, 3]))
@@ -142,6 +143,17 @@ class TestIDGenerator:
         assert transformer._counter == 3
 
 
+class TestIDGenerator:
+    def test___init__(self):
+        """Test the warning message for ``IDGenerator``."""
+        msg = re.escape(
+            "The 'IDGenerator' has been renamed to 'IndexGenerator'. Please update the"
+            'name to ensure compatibility with future versions of RDT.'
+        )
+        with pytest.warns(FutureWarning, match=msg):
+            IDGenerator(prefix='prefix_', starting_value=100, suffix='_suffix')
+
+
 class TestRegexGenerator:
     """Test class for ``RegexGenerator``."""