pitrou commented on code in PR #47977:
URL: https://github.com/apache/arrow/pull/47977#discussion_r2469662726


##########
python/pyarrow/pandas_compat.py:
##########
@@ -277,6 +277,15 @@ def construct_metadata(columns_to_convert, df, 
column_names, index_levels,
 
     attributes = df.attrs if hasattr(df, "attrs") else {}
 
+    try:
+        json.dumps(attributes)
+    except (TypeError, OverflowError):

Review Comment:
   Can we just catch any `Exception`? Other errors might perhaps be raised.



##########
python/pyarrow/pandas_compat.py:
##########
@@ -277,6 +277,15 @@ def construct_metadata(columns_to_convert, df, 
column_names, index_levels,
 
     attributes = df.attrs if hasattr(df, "attrs") else {}
 
+    try:
+        json.dumps(attributes)
+    except (TypeError, OverflowError):
+        attributes = {}
+        warnings.warn(
+            "Could not serialize pd.attrs, "

Review Comment:
   ```suggestion
               "Could not serialize pd.DataFrame.attrs, "
   ```



##########
python/pyarrow/pandas_compat.py:
##########
@@ -277,6 +277,15 @@ def construct_metadata(columns_to_convert, df, 
column_names, index_levels,
 
     attributes = df.attrs if hasattr(df, "attrs") else {}
 
+    try:
+        json.dumps(attributes)
+    except (TypeError, OverflowError):
+        attributes = {}
+        warnings.warn(
+            "Could not serialize pd.attrs, "
+            "defaulting to empty attributes",
+            UserWarning, stacklevel=4)

Review Comment:
   Can we include the original exception text in the warning message?



-- 
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