larray-project / larray

N-dimensional labelled arrays in Python
https://larray.readthedocs.io/
GNU General Public License v3.0
8 stars 6 forks source link

Some newer version of Pandas throws warnings #1061

Closed gdementen closed 10 months ago

gdementen commented 1 year ago

When running moses_git\rework2022\src\main.py with my updated environment (larray 0.34 et al), I get the following warning:

[...]\py39larrayenv\lib\site-packages\larray\core\array.py:1551: FutureWarning: In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences (matching Series behavior)
  index = pd.Index(data=self.axes[0].labels, name=axes_names[0])
gdementen commented 1 year ago

Another line causing the same warning (I will have to check all uses of pd.Index()):

[...]\larray\core\array.py:1541: FutureWarning: In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences (matching Series behavior)
  columns = pd.Index(self.axes[-1].labels)
gdementen commented 1 year ago

This happens when we have a numpy array of object dtype which only contains numeric values, which Pandas currently converts to a numeric index (e.g. Int64Index) instead of a generic/object Index (and will no longer do that)

Minimal test case:

>>> arr = ndtest("a=0..2").with_total()[:2]
>>> pd.Index(arr.a.labels)
FutureWarning: In a future version, the Index constructor will not infer numeric dtypes when passed object-dtype sequences (matching Series behavior)
gdementen commented 1 year ago

This was introduced in Pandas 1.4. See https://github.com/pandas-dev/pandas/pull/42870