@@ -199,17 +199,16 @@ def __next__(self):
199199 except IndexError :
200200 raise StopIteration
201201
202- def to_df (self , columns : list = None ): # For backwards compatibility (jgray 2024)
202+ def to_df (self , columns : list = None , force_pandas : bool = False ): # For backwards compatibility (jgray 2024)
203203 """See `convert_to_dataframe`"""
204- return self .convert_to_dataframe (columns )
204+ return self .convert_to_dataframe (columns , force_pandas )
205205
206- def convert_to_dataframe (self , columns : list = None ):
206+ def convert_to_dataframe (self , columns : list = None , force_pandas : bool = False ):
207207 """Converts the object to a pandas dataframe.
208208
209- This function imports pandas and tfs-pandas, if tfs-pandas is not installed, it will only return a pandas dataframe.
210-
211209 Args:
212210 columns (list, optional): List of columns to include in the dataframe. Defaults to None.
211+ force_pandas (bool, optional): If True, always use pandas.DataFrame. Defaults to False.
213212
214213 Returns:
215214 pandas.DataFrame or tfs.TfsDataFrame: The dataframe containing the object's data.
@@ -227,7 +226,10 @@ def convert_to_dataframe(self, columns: list = None):
227226 # If tfs is available, use the headers attribute
228227 DataFrame , hdr_attr = tfs .TfsDataFrame , "headers"
229228 except ImportError :
230- # Otherwise, use the pandas dataframe and attrs attribute
229+ force_pandas = True
230+
231+ if force_pandas :
232+ # If pandas is the only option, use pandas DataFrame, with the attrs attribute
231233 DataFrame , hdr_attr = pd .DataFrame , "attrs"
232234
233235 py_name , obj_name = self ._mad .py_name , self ._name
0 commit comments