korbit-ai[bot] commented on code in PR #35586:
URL: https://github.com/apache/superset/pull/35586#discussion_r2417710259


##########
superset/commands/database/uploaders/csv_reader.py:
##########
@@ -357,7 +357,28 @@ def _read_csv(  # noqa: C901
         kwargs["low_memory"] = False
 
         try:
-            types = kwargs.pop("dtype", None)
+            # Only pop types that are not str or object
+            original_types = kwargs.get("dtype", None)
+            types = None
+            if original_types:
+                # keep str/object in kwargs, extract others for custom casting
+                pandas_types = {}
+                custom_types = {}

Review Comment:
   ### Missing type handling encapsulation <sub>![category 
Design](https://img.shields.io/badge/Design-0d9488)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   Type handling logic is embedded within the _read_csv method instead of being 
encapsulated in a dedicated type handling class or method.
   
   
   ###### Why this matters
   Mixing type handling with CSV reading logic reduces code reusability and 
makes it harder to modify type handling behavior independently.
   
   ###### Suggested change ∙ *Feature Preview*
   Create a dedicated TypeHandler class:
   ```python
   class CSVTypeHandler:
       def split_types(self, types: dict[str, str]) -> tuple[dict[str, str], 
dict[str, str]]:
           pandas_types = {col: dtype for col, dtype in types.items() if dtype 
in ('str', 'object', 'string')}
           custom_types = {col: dtype for col, dtype in types.items() if dtype 
not in ('str', 'object', 'string')}
           return pandas_types, custom_types
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice 
Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/a736bb38-bf95-47ff-9369-3b100dbe7f46/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/a736bb38-bf95-47ff-9369-3b100dbe7f46?what_not_true=true)
  [![Not in 
Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/a736bb38-bf95-47ff-9369-3b100dbe7f46?what_out_of_scope=true)
 [![Not in coding 
standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/a736bb38-bf95-47ff-9369-3b100dbe7f46?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/a736bb38-bf95-47ff-9369-3b100dbe7f46)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:f8dd1a16-addf-4635-8e47-17617b73a291 -->
   
   
   [](f8dd1a16-addf-4635-8e47-17617b73a291)



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to