@@ -95,44 +95,21 @@ def copy_to_readonly_numpy_array(v, kind=None, force_numeric=False):
9595 }
9696
9797 if isinstance (v , nw .Series ):
98- if nw .dependencies .is_pandas_like_series (v_native := v .to_native ()):
99- v = v_native
98+ if v .dtype == nw .Datetime and v .dtype .time_zone is not None :
99+ # Remove time zone so that local time is displayed
100+ v = v .dt .replace_time_zone (None ).to_numpy ()
100101 else :
101102 v = v .to_numpy ()
102103 elif isinstance (v , nw .DataFrame ):
103- if nw .dependencies .is_pandas_like_dataframe (v_native := v .to_native ()):
104- v = v_native
105- else :
106- v = v .to_numpy ()
107-
108- if pd and isinstance (v , (pd .Series , pd .Index )):
109- # Handle pandas Series and Index objects
110- if v .dtype .kind in numeric_kinds :
111- # Get the numeric numpy array so we use fast path below
112- v = v .values
113- elif v .dtype .kind == "M" :
114- # Convert datetime Series/Index to numpy array of datetimes
115- if isinstance (v , pd .Series ):
116- with warnings .catch_warnings ():
117- warnings .simplefilter ("ignore" , FutureWarning )
118- # Series.dt.to_pydatetime will return Index[object]
119- # https://github.com/pandas-dev/pandas/pull/52459
120- v = np .array (v .dt .to_pydatetime ())
121- else :
122- # DatetimeIndex
123- v = v .to_pydatetime ()
124- elif pd and isinstance (v , pd .DataFrame ) and len (set (v .dtypes )) == 1 :
125- dtype = v .dtypes .tolist ()[0 ]
126- if dtype .kind in numeric_kinds :
127- v = v .values
128- elif dtype .kind == "M" :
129- with warnings .catch_warnings ():
130- warnings .simplefilter ("ignore" , FutureWarning )
131- # Series.dt.to_pydatetime will return Index[object]
132- # https://github.com/pandas-dev/pandas/pull/52459
133- v = [
134- np .array (row .dt .to_pydatetime ()).tolist () for i , row in v .iterrows ()
135- ]
104+ schema = v .schema
105+ overrides = {}
106+ for key , val in schema .items ():
107+ if val == nw .Datetime and val .time_zone is not None :
108+ # Remove time zone so that local time is displayed
109+ overrides [key ] = nw .col (key ).dt .replace_time_zone (None )
110+ if overrides :
111+ v = v .with_columns (** overrides )
112+ v = v .to_numpy ()
136113
137114 if not isinstance (v , np .ndarray ):
138115 # v has its own logic on how to convert itself into a numpy array
0 commit comments