Repository: CartoDB/cartoframes
Pull request #1660 (2020-07-01 06:40:21)

Fix bug in ColumnInfo comparison


Patch:
diff --git a/cartoframes/io/managers/context_manager.py b/cartoframes/io/managers/context_manager.py
index 6481164a..df6fcee4 100644
--- a/cartoframes/io/managers/context_manager.py
+++ b/cartoframes/io/managers/context_manager.py
@@ -219,10 +219,8 @@ class ContextManager:
         return tables
 
     def _compare_columns(self, a, b):
-        GEOM_COL = 'the_geom_webmercator'
-
-        a_copy = [i for i in a if (i.name != GEOM_COL)]
-        b_copy = [i for i in b if (i.name != GEOM_COL)]
+        a_copy = [i for i in a if _not_reserved(i.name)]
+        b_copy = [i for i in b if _not_reserved(i.name)]
 
         a_copy.sort()
         b_copy.sort()
diff --git a/cartoframes/utils/columns.py b/cartoframes/utils/columns.py
index 37e00cce..037aef64 100644
--- a/cartoframes/utils/columns.py
+++ b/cartoframes/utils/columns.py
@@ -39,26 +39,21 @@ class ColumnInfo:
         return 'ColumnInfo({})'.format(params)
 
     def __eq__(self, other):
-        if self.name == 'cartodb_id':
-            # Skip cartodb_id comparison because cartodbfy converts bigint to integer
-            return True
-        else:
-            return self.name == other.name and \
-                   self.dbname == other.dbname and \
-                   self.dbtype == other.dbtype and \
-                   self.is_geom == other.is_geom
+        return self.dbname == other.dbname and \
+                self.dbtype == other.dbtype and \
+                self.is_geom == other.is_geom
 
     def __gt__(self, other):
-        return self.name > other.name
+        return self.dbname > other.dbname
 
     def __ge__(self, other):
-        return self.name >= other.name
+        return self.dbname >= other.dbname
 
     def __lt__(self, other):
-        return self.name < other.name
+        return self.dbname < other.dbname
 
     def __le__(self, other):
-        return self.name <= other.name
+        return self.dbname <= other.dbname
 
 
 def get_dataframe_columns_info(df):


Test patch:
diff --git a/tests/unit/utils/test_columns.py b/tests/unit/utils/test_columns.py
index 157c0232..e532e806 100644
--- a/tests/unit/utils/test_columns.py
+++ b/tests/unit/utils/test_columns.py
@@ -133,3 +133,27 @@ class TestColumns(object):
         assert converters['name'] == _convert_generic
         assert converters['flag'] == _convert_bool
         assert converters['number'] == _convert_float
+
+    def test_column_info_sort(self):
+        columns = [
+            ColumnInfo('cartodb_id', 'cartodb_id', 'integer', False),
+            ColumnInfo('the_geom', 'the_geom', 'geometry(Geometry, 4326)', True),
+            ColumnInfo('Name', 'name', 'text', False),
+            ColumnInfo('flag', 'flag', 'boolean', False),
+            ColumnInfo('NUMBER', 'number', 'double precision', False)
+        ]
+
+        columns.sort()
+
+        assert columns == [
+            ColumnInfo('cartodb_id', 'cartodb_id', 'integer', False),
+            ColumnInfo('flag', 'flag', 'boolean', False),
+            ColumnInfo('Name', 'name', 'text', False),
+            ColumnInfo('NUMBER', 'number', 'double precision', False),
+            ColumnInfo('the_geom', 'the_geom', 'geometry(Geometry, 4326)', True)
+        ]
+
+    def test_column_info_compare(self):
+        column = ColumnInfo('cartodb_id', 'cartodb_id', 'integer', False)
+
+        assert column == ColumnInfo('CARTODB_ID', 'cartodb_id', 'integer', False)