# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=pandas
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.2.3
pkgrel=2
pkgdesc="Powerful data structures for data analysis, time series, and statistics (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://pandas.pydata.org/"
msys2_repository_url="https://github.com/pandas-dev/pandas"
msys2_references=(
  'purl: pkg:pypi/pandas'
  "cpe: cpe:/a:numfocus:pandas"
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-python-dateutil"
         "${MINGW_PACKAGE_PREFIX}-python-pytz"
         "${MINGW_PACKAGE_PREFIX}-python-tzdata")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-versioneer"
             "${MINGW_PACKAGE_PREFIX}-meson-python"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cc")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-scipy: needed for miscellaneous statistical functions"
            "${MINGW_PACKAGE_PREFIX}-python-matplotlib: needed for plotting"
            "${MINGW_PACKAGE_PREFIX}-python-numexpr: needed for accelerating certain numerical operations (recommended)"
            "${MINGW_PACKAGE_PREFIX}-python-openpyxl: needed for reading/writing Excel file")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "001-dont-search-for-vs.patch")
sha256sums=('4f18ba62b61d7e192368b84517265a99b4d7ee8912f8708660fb4a366cc82667'
            'b154f79517b36cd16b8905a19effd9d218f4239ffedbaf066ca6c45f91edc728')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-dont-search-for-vs.patch
}

build() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  # Remove unneeded import libraries
  rm -f "${pkgdir}"${MINGW_PREFIX}/lib/python3.11/site-packages/pandas/_libs/*.dll.a
  rm -f "${pkgdir}"${MINGW_PREFIX}/lib/python3.11/site-packages/pandas/_libs/*/*.dll.a

  install -Dm644 LICENSE \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
