From 2964e052d3959356576d290efdd83b1dc2795af4 Mon Sep 17 00:00:00 2001 From: Cristiano Singulani Date: Tue, 21 May 2024 19:51:50 +0000 Subject: [PATCH] Fixed error that occurred when reading a fits file and converting it to pandas using tables_io and python in version 3.10. --- requirements.txt | 2 +- src/pzserver/catalog.py | 4 ++-- src/pzserver/core.py | 11 +++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index cac94cd..738af62 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ pandas>=1.2.0 requests>=2.23.0 astropy>=5.0.0 matplotlib>=3.6.0 -tables_io>=0.7.9 +tables_io>=0.9.6 Jinja2>=3.1.2 ipython>=8.5.0 h5py>=3.8.0 diff --git a/src/pzserver/catalog.py b/src/pzserver/catalog.py index ac4fc0b..9fa3c59 100644 --- a/src/pzserver/catalog.py +++ b/src/pzserver/catalog.py @@ -3,7 +3,6 @@ """ import matplotlib.pyplot as plt -import pandas as pd from IPython.display import display @@ -16,7 +15,8 @@ def __init__(self, data=None, metadata=None, metadata_df=None): """ Catalog class constructor """ - self.data = pd.DataFrame(data) + + self.data = data self.metadata = metadata self.columns = metadata.get("main_file").get("columns_association") self.metadata_df = metadata_df diff --git a/src/pzserver/core.py b/src/pzserver/core.py index 801ccc1..95e1685 100644 --- a/src/pzserver/core.py +++ b/src/pzserver/core.py @@ -377,13 +377,16 @@ def get_product(self, product_id=None, fmt=None): return dataframe results = self.__transform_df(dataframe, metadata) else: + dataframe = tables_io.read(file_path) # default types in Astropy Table + if fmt == "astropy": - return tables_io.read(file_path, tType=tables_io.types.AP_TABLE) - dataframe = tables_io.read( - file_path, tType=tables_io.types.PD_DATAFRAME - ) + return dataframe + + dataframe = dataframe.to_pandas() + if fmt == "pandas": return dataframe + results = self.__transform_df(dataframe, metadata) print("Done!")