jorisvandenbossche commented on code in PR #49878:
URL: https://github.com/apache/arrow/pull/49878#discussion_r3182439892


##########
python/pyarrow/tests/test_pandas.py:
##########
@@ -492,6 +492,22 @@ def test_categorical_row_index(self):
 
         _check_pandas_roundtrip(df, preserve_index=True)
 
+    def test_categorical_with_timezone(self):
+        # pandas Categorical with timezone-aware datetime categories
+        # GH-49875: timezone was dropped when converting tz-aware categorical
+        cats = pd.DatetimeIndex(["2024-01-01", 
"2024-01-02"]).tz_localize("US/Eastern")
+        cat = pd.Categorical(values=[cats[0], cats[1], cats[0]], 
categories=cats)
+
+        # Verify pandas keeps the timezone on categories
+        assert "US/Eastern" in str(cat.dtype.categories.dtype)
+
+        # Convert to PyArrow

Review Comment:
   ```suggestion
   ```
   
   (let's remove some unnecessary comments and checks, we just want to verify 
that the converted array has the correct tz)



##########
python/pyarrow/tests/test_pandas.py:
##########
@@ -492,6 +492,22 @@ def test_categorical_row_index(self):
 
         _check_pandas_roundtrip(df, preserve_index=True)
 
+    def test_categorical_with_timezone(self):
+        # pandas Categorical with timezone-aware datetime categories
+        # GH-49875: timezone was dropped when converting tz-aware categorical
+        cats = pd.DatetimeIndex(["2024-01-01", 
"2024-01-02"]).tz_localize("US/Eastern")
+        cat = pd.Categorical(values=[cats[0], cats[1], cats[0]], 
categories=cats)
+
+        # Verify pandas keeps the timezone on categories
+        assert "US/Eastern" in str(cat.dtype.categories.dtype)
+
+        # Convert to PyArrow
+        arr = pa.array(cat, from_pandas=True)
+
+        # Verify timezone is preserved in the dictionary value type
+        assert arr.type.value_type.tz is not None
+        assert str(arr.type.value_type.tz) == "US/Eastern"

Review Comment:
   ```suggestion
           assert arr.type.value_type.tz == "US/Eastern"
   ```
   
   The `.tz` attribute is already a string



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to