From 796b1fa9d1cc5a4387b3d122e338b15fa1af4018 Mon Sep 17 00:00:00 2001 From: Yousuf Ali Date: Mon, 2 Oct 2023 13:44:31 -0400 Subject: [PATCH] support for xpt file --- pandasgui/gui.py | 2 +- pandasgui/run_with_args.py | 6 ++++-- pandasgui/store.py | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pandasgui/gui.py b/pandasgui/gui.py index 3b85b2b..f5c1f1a 100644 --- a/pandasgui/gui.py +++ b/pandasgui/gui.py @@ -330,7 +330,7 @@ def __getitem__(self, key): def import_dialog(self): dialog = QtWidgets.QFileDialog() - paths, _ = dialog.getOpenFileNames(filter="*.csv *.xlsx *.parquet *.json") + paths, _ = dialog.getOpenFileNames(filter="*.csv *.xlsx *.parquet *.json *.xpt") for path in paths: self.store.import_file(path) diff --git a/pandasgui/run_with_args.py b/pandasgui/run_with_args.py index 525e6dc..0b589a4 100644 --- a/pandasgui/run_with_args.py +++ b/pandasgui/run_with_args.py @@ -11,11 +11,13 @@ def main(): if file_paths: file_dataframes = {} for path in file_paths: - if os.path.isfile(path) and (path.endswith('.csv') or path.endswith('.pkl')): + if os.path.isfile(path) and (path.endswith('.csv') or path.endswith('.pkl') or path.endswith('.xpt')): if path.endswith('.csv') : df = pd.read_csv(path) if path.endswith('.pkl'): df = pd.read_pickle(path) + if path.endswith('.xpt') : + df = pd.read_sas(path, encoding='utf-8') filename = os.path.split(path)[1] file_dataframes[filename] = df show(**file_dataframes) @@ -25,4 +27,4 @@ def main(): input() if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/pandasgui/store.py b/pandasgui/store.py index 0c5f5b3..9519f5a 100644 --- a/pandasgui/store.py +++ b/pandasgui/store.py @@ -834,6 +834,10 @@ def import_file(self, path): filename = os.path.split(path)[1].split('.csv')[0] df = pd.read_csv(path, engine='python') self.add_dataframe(df, filename) + elif path.endswith(".xpt"): + filename = os.path.split(path)[1].split('.xpt')[0] + df = pd.read_sas(path, encoding='utf-8') + self.add_dataframe(df, filename) elif path.endswith(".xlsx"): filename = os.path.split(path)[1].split('.csv')[0] df_dict = pd.read_excel(path, sheet_name=None) @@ -856,7 +860,7 @@ def import_file(self, path): df = pd.read_pickle(path) self.add_dataframe(df, filename) else: - logger.warning("Can only import csv / xlsx / parquet. Invalid file: " + path) + logger.warning("Can only import csv / xlsx / parquet/ xpt. Invalid file: " + path) def get_dataframes(self, names: Union[None, str, list, int] = None): if type(names) == str: