@@ -202,17 +202,16 @@ def __next__(self):
202202 except IndexError :
203203 raise StopIteration
204204
205- def to_df (self , columns : list = None ): # For backwards compatibility (jgray 2024)
205+ def to_df (self , columns : list = None , force_pandas : bool = False ): # For backwards compatibility (jgray 2024)
206206 """See `convert_to_dataframe`"""
207- return self .convert_to_dataframe (columns )
207+ return self .convert_to_dataframe (columns , force_pandas )
208208
209- def convert_to_dataframe (self , columns : list = None ):
209+ def convert_to_dataframe (self , columns : list = None , force_pandas : bool = False ):
210210 """Converts the object to a pandas dataframe.
211211
212- This function imports pandas and tfs-pandas, if tfs-pandas is not installed, it will only return a pandas dataframe.
213-
214212 Args:
215213 columns (list, optional): List of columns to include in the dataframe. Defaults to None.
214+ force_pandas (bool, optional): If True, always use pandas.DataFrame. Defaults to False.
216215
217216 Returns:
218217 pandas.DataFrame or tfs.TfsDataFrame: The dataframe containing the object's data.
@@ -230,7 +229,10 @@ def convert_to_dataframe(self, columns: list = None):
230229 # If tfs is available, use the headers attribute
231230 DataFrame , hdr_attr = tfs .TfsDataFrame , "headers"
232231 except ImportError :
233- # Otherwise, use the pandas dataframe and attrs attribute
232+ force_pandas = True
233+
234+ if force_pandas :
235+ # If pandas is the only option, use pandas DataFrame, with the attrs attribute
234236 DataFrame , hdr_attr = pd .DataFrame , "attrs"
235237
236238 py_name , obj_name = self ._mad .py_name , self ._name
0 commit comments