uclchem / SpectralRadex

A Python library for spectral modelling and RADEX
MIT License
17 stars 3 forks source link

Address deprecated features in Pandas 2.0 #9

Open GijsVermarien opened 1 year ago

GijsVermarien commented 1 year ago

Several things are deprecated in Pandas 2.0, such as appending dataframes (see https://github.com/pandas-dev/pandas/issues/35407).

This needs to be fixed to get the code up to date for new installs.

For now a solution is to install the package with pandas 1.5.3 https://pandas.pydata.org/docs/whatsnew/v1.5.3.html

jonholdship commented 1 year ago

Probably best to replace append with pd.concat

GijsVermarien commented 1 year ago

Yes! There might be more pandas deprecations lingering around, such as not being able to write array elements to one pandas column, see: https://github.com/uclchem/SpectralRadex/commit/0dff9b74ad9bf4d0d4d3bf20e949252ed90d9b04

So I will try to comb through all of the code and possibly write some tests to make sure we cover the code.

jpinedaf commented 1 year ago

Hi,

I was trying to use the option for running grids, but I got hit by this bug. Is there any progress on fixing this issue?

tic = time.perf_counter()
pool = Pool(8)
grid_df = radex.run_grid(parameters_g, target_value='FLUX (K*km/s)', pool=pool)
toc = time.perf_counter()
print(f"total time {toc-tic:0.4f} seconds without a pool")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/w3/6j3w0gvj09b442gm4ysq3gmw0000gn/T/ipykernel_30181/385791336.py in ?()
      1 tic = time.perf_counter()
      2 pool = Pool(8)
----> 3 grid_df = radex.run_grid(parameters_g, target_value='FLUX (K*km/s)', pool=pool)
      4 toc = time.perf_counter()
      5 print(f"total time {toc-tic:0.4f} seconds without a pool")

~/miniconda3/envs/astro/lib/python3.11/site-packages/spectralradex/radex/__init__.py in ?(parameters, target_value, pool)
    170         pool_results = pool.map(func, parameter_combinations)
    171         pool.close()
    172         pool.join()
    173         pool_results_df = concat(pool_results, axis=0)
--> 174         output = output.append(pool_results_df, ignore_index=True)
    175     else:
    176         for grid_point in range(len(parameter_combinations)):
    177             output = output.append(format_run_for_grid(line_count, parameters,

~/miniconda3/envs/astro/lib/python3.11/site-packages/pandas/core/generic.py in ?(self, name)
   6198             and name not in self._accessors
   6199             and self._info_axis._can_hold_identifiers_and_holds_name(name)
   6200         ):
   6201             return self[name]
-> 6202         return object.__getattribute__(self, name)

AttributeError: 'DataFrame' object has no attribute 'append'

I am using pandas version 2.1.0.

GijsVermarien commented 1 year ago

Hi Jaime,

Unfortunately we do not support pandas > 2.0 for now. Please downgrade to the latest supported version: https://pandas.pydata.org/docs/whatsnew/v1.5.3.html

Best,

Gijs