From 0b9255604fcefa9deb1b7c526041af5885b13b23 Mon Sep 17 00:00:00 2001 From: jorenham Date: Wed, 9 Oct 2024 19:39:36 +0200 Subject: [PATCH] deal with deprecated `scipy.constants` modules --- scipy-stubs/constants/__init__.pyi | 173 +++++++++++++- scipy-stubs/constants/_codata.pyi | 28 +-- scipy-stubs/constants/_constants.pyi | 335 ++++++++++++++------------- scipy-stubs/constants/codata.pyi | 4 + scipy-stubs/constants/constants.pyi | 314 +++++++++++++++++++++++++ tests/stubtest/allowlist.txt | 22 +- 6 files changed, 681 insertions(+), 195 deletions(-) create mode 100644 scipy-stubs/constants/codata.pyi create mode 100644 scipy-stubs/constants/constants.pyi diff --git a/scipy-stubs/constants/__init__.pyi b/scipy-stubs/constants/__init__.pyi index 88460ad1..2fe2362c 100644 --- a/scipy-stubs/constants/__init__.pyi +++ b/scipy-stubs/constants/__init__.pyi @@ -1,7 +1,172 @@ -from . import _codata, _constants +from . import codata, constants from ._codata import * from ._constants import * -__all__: list[str] = [] -__all__ += _codata.__all__ -__all__ += _constants.__all__ +__all__ = [ + "N_A", + "Avogadro", + "Boltzmann", + "Btu", + "Btu_IT", + "Btu_th", + "ConstantWarning", + "G", + "Julian_year", + "Planck", + "R", + "Rydberg", + "Stefan_Boltzmann", + "Wien", + "acre", + "alpha", + "angstrom", + "arcmin", + "arcminute", + "arcsec", + "arcsecond", + "astronomical_unit", + "atm", + "atmosphere", + "atomic_mass", + "atto", + "au", + "bar", + "barrel", + "bbl", + "blob", + "c", + "calorie", + "calorie_IT", + "calorie_th", + "carat", + "centi", + "codata", + "constants", + "convert_temperature", + "day", + "deci", + "degree", + "degree_Fahrenheit", + "deka", + "dyn", + "dyne", + "e", + "eV", + "electron_mass", + "electron_volt", + "elementary_charge", + "epsilon_0", + "erg", + "exa", + "exbi", + "femto", + "fermi", + "find", + "fine_structure", + "fluid_ounce", + "fluid_ounce_US", + "fluid_ounce_imp", + "foot", + "g", + "gallon", + "gallon_US", + "gallon_imp", + "gas_constant", + "gibi", + "giga", + "golden", + "golden_ratio", + "grain", + "gram", + "gravitational_constant", + "h", + "hbar", + "hectare", + "hecto", + "horsepower", + "hour", + "hp", + "inch", + "k", + "kgf", + "kibi", + "kilo", + "kilogram_force", + "kmh", + "knot", + "lambda2nu", + "lb", + "lbf", + "light_year", + "liter", + "litre", + "long_ton", + "m_e", + "m_n", + "m_p", + "m_u", + "mach", + "mebi", + "mega", + "metric_ton", + "micro", + "micron", + "mil", + "mile", + "milli", + "minute", + "mmHg", + "mph", + "mu_0", + "nano", + "nautical_mile", + "neutron_mass", + "nu2lambda", + "ounce", + "oz", + "parsec", + "pebi", + "peta", + "physical_constants", + "pi", + "pico", + "point", + "pound", + "pound_force", + "precision", + "proton_mass", + "psi", + "pt", + "quecto", + "quetta", + "ronna", + "ronto", + "short_ton", + "sigma", + "slinch", + "slug", + "speed_of_light", + "speed_of_sound", + "stone", + "survey_foot", + "survey_mile", + "tebi", + "tera", + "ton_TNT", + "torr", + "troy_ounce", + "troy_pound", + "u", + "unit", + "value", + "week", + "yard", + "year", + "yobi", + "yocto", + "yotta", + "zebi", + "zepto", + "zero_Celsius", + "zetta", +] diff --git a/scipy-stubs/constants/_codata.pyi b/scipy-stubs/constants/_codata.pyi index 729c69d6..11181b55 100644 --- a/scipy-stubs/constants/_codata.pyi +++ b/scipy-stubs/constants/_codata.pyi @@ -1,3 +1,4 @@ +from collections.abc import Mapping from typing import Final, Literal, TypeAlias from typing_extensions import LiteralString @@ -84,11 +85,11 @@ _Unit: TypeAlias = Literal[ "u", ] _Constant: TypeAlias = tuple[float, _Unit, float] -_ConstantDict: TypeAlias = dict[LiteralString, _Constant] +_Constants: TypeAlias = Mapping[str, _Constant] # public -physical_constants: Final[_ConstantDict] +physical_constants: Final[_Constants] class ConstantWarning(DeprecationWarning): ... @@ -99,16 +100,17 @@ def precision(key: str) -> float: ... # private -txt2002: Final[str] -txt2006: Final[str] -txt2010: Final[str] -txt2014: Final[str] -txt2018: Final[str] +txt2002: Final[str] = ... +txt2006: Final[str] = ... +txt2010: Final[str] = ... +txt2014: Final[str] = ... +txt2018: Final[str] = ... -def parse_constants_2002to2014(d: str) -> _ConstantDict: ... -def parse_constants_2018toXXXX(d: str) -> _ConstantDict: ... +exact_values: Final[_Constants] = ... +c: Final = 299792458.0 +mu0: Final = 1.25663706212e-06 +epsilon0: Final = 8.8541878128e-12 +k: Final = "electric constant" -c: Final[float] -mu0: Final[float] -epsilon0: Final[float] -exact_values: Final[_ConstantDict] +def parse_constants_2002to2014(d: str) -> _Constants: ... +def parse_constants_2018toXXXX(d: str) -> _Constants: ... diff --git a/scipy-stubs/constants/_constants.pyi b/scipy-stubs/constants/_constants.pyi index 216e4f3f..ea19e98d 100644 --- a/scipy-stubs/constants/_constants.pyi +++ b/scipy-stubs/constants/_constants.pyi @@ -1,7 +1,8 @@ -from typing import Literal +from typing import Final, Literal, TypeAlias import numpy as np import numpy.typing as npt +from numpy._typing import _ArrayLikeFloat_co __all__ = [ "N_A", @@ -164,197 +165,205 @@ __all__ = [ "zetta", ] +_TempScaleC: TypeAlias = Literal["Celsius", "celsius", "C", "c"] +_TempScaleK: TypeAlias = Literal["Kelvin", "kelvin", "K", "k"] +_TempScaleF: TypeAlias = Literal["Fahrenheit", "fahrenheit", "F", "f"] +_TempScaleR: TypeAlias = Literal["Rankine", "rankine", "R", "r"] +_TempScale: TypeAlias = Literal[_TempScaleC, _TempScaleK, _TempScaleF, _TempScaleR] + # mathematical constants -pi: float -golden: float -golden_ratio: float +pi: Final = 3.141592653589793 +golden: Final = 1.618033988749895 +golden_ratio: Final = 1.618033988749895 # SI prefixes -quetta: float -ronna: float -yotta: float -zetta: float -exa: float -peta: float -tera: float -giga: float -mega: float -kilo: float -hecto: float -deka: float -deci: float -centi: float -milli: float -micro: float -nano: float -pico: float -femto: float -atto: float -zepto: float -yocto: float -ronto: float -quecto: float +quetta: Final = 1e30 +ronna: Final = 1e27 +yotta: Final = 1e24 +zetta: Final = 1e21 +exa: Final = 1e18 +peta: Final = 1e15 +tera: Final = 1e12 +giga: Final = 1e9 +mega: Final = 1e6 +kilo: Final = 1e3 +hecto: Final = 1e2 +deka: Final = 1e1 +deci: Final = 1e-1 +centi: Final = 1e-2 +milli: Final = 1e-3 +micro: Final = 1e-6 +nano: Final = 1e-9 +pico: Final = 1e-12 +femto: Final = 1e-15 +atto: Final = 1e-18 +zepto: Final = 1e-21 +yocto: Final = 1e-24 +ronto: Final = 1e-27 +quecto: Final = 1e-30 # binary prefixes -# ruff: noqa: PYI054 -kibi: Literal[0x400] -mebi: Literal[0x100000] -gibi: Literal[0x40000000] -tebi: Literal[0x10000000000] -pebi: Literal[0x4000000000000] -exbi: Literal[0x1000000000000000] -zebi: Literal[0x400000000000000000] -yobi: Literal[0x100000000000000000000] +kibi: Final = 0x400 +mebi: Final = 0x10_0000 +gibi: Final = 0x4000_0000 +tebi: Final = 0x100_0000_0000 +pebi: Final = 0x4_0000_0000_0000 +exbi: Final = 0x1000_0000_0000_0000 +zebi: Final = 0x40_0000_0000_0000_0000 +yobi: Final = 0x1_0000_0000_0000_0000_0000 # physical constants -c: float -speed_of_light: float -mu_0: float -epsilon_0: float -h: float -Planck: float -hbar: float -G: float -gravitational_constant: float -g: float -e: float -elementary_charge: float -R: float -gas_constant: float -alpha: float -fine_structure: float -N_A: float -Avogadro: float -k: float -Boltzmann: float -sigma: float -Stefan_Boltzmann: float -Wien: float -Rydberg: float +c: Final = 299792458.0 +speed_of_light: Final = 299792458.0 +mu_0: Final = 1.25663706212e-6 +epsilon_0: Final = 8.8541878128e-12 +h: Final = 6.62607015e-34 +Planck: Final = 6.62607015e-34 +hbar: Final = 1.0545718176461565e-34 +G: Final = 6.6743e-11 +gravitational_constant: Final = 6.6743e-11 +g: Final = 9.80665 +e: Final = 1.602176634e-19 +elementary_charge: Final = 1.602176634e-19 +R: Final = 8.314462618 +gas_constant: Final = 8.314462618 +alpha: Final = 0.0072973525693 +fine_structure: Final = 0.0072973525693 +N_A: Final = 6.02214076e23 +Avogadro: Final = 6.02214076e23 +k: Final = 1.380649e-23 +Boltzmann: Final = 1.380649e-23 +sigma: Final = 5.670374419e-8 +Stefan_Boltzmann: Final = 5.670374419e-8 +Wien: Final = 0.002897771955 +Rydberg: Final = 10973731.56816 # mass in kg -gram: float -metric_ton: float -grain: float -lb: float -pound: float -blob: float -slinch: float -slug: float -oz: float -ounce: float -stone: float -long_ton: float -short_ton: float - -troy_ounce: float -troy_pound: float -carat: float - -m_e: float -electron_mass: float -m_p: float -proton_mass: float -m_n: float -neutron_mass: float -m_u: float -u: float -atomic_mass: float +gram: Final = 1e-3 +metric_ton: Final = 1e3 +# legacy mass units +grain: Final = 6.479891e-5 +lb: Final = 0.45359237 +pound: Final = 0.45359237 +blob: Final = 175.12683524647636 +slinch: Final = 175.12683524647636 +slug: Final = 14.593902937206364 +oz: Final = 0.028349523125 +ounce: Final = 0.028349523124 +stone: Final = 6.35029318 +long_ton: Final = 1.0160469088e3 +short_ton: Final = 907.18474 +troy_ounce: Final = 0.0311034768 +troy_pound: Final = 0.3732417216 +carat: Final = 2e-4 +# fundamental masses +m_e: Final = 9.1093837015e-31 +electron_mass: Final = 9.1093837015e-31 +m_p: Final = 1.67262192369e-27 +proton_mass: Final = 1.67262192369e-27 +m_n: Final = 1.67492749804e-27 +neutron_mass: Final = 1.67492749804e-27 +m_u: Final = 1.6605390666e-27 +u: Final = 1.6605390666e-27 +atomic_mass: Final = 1.6605390666e-27 # angle in rad -degree: float -arcmin: float -arcminute: float -arcsec: float -arcsecond: float +degree: Final = 0.017453292519943295 +arcmin: Final = 2.908882086657216e-4 +arcminute: Final = 2.908882086657216e-4 +arcsec: Final = 4.84813681109536e-6 +arcsecond: Final = 4.84813681109536e-6 # time in second -minute: float -hour: float -day: float -week: float -year: float -Julian_year: float +minute: Final = 60.0 +hour: Final = 3_600.0 +day: Final = 86_400.0 +week: Final = 604_800.0 +year: Final = 31_536_000.0 +Julian_year: Final = 31_557_600.0 # length in meter -inch: float -foot: float -yard: float -mile: float -mil: float -pt: float -point: float -survey_foot: float -survey_mile: float -nautical_mile: float -fermi: float -angstrom: float -micron: float -au: float -astronomical_unit: float -light_year: float -parsec: float +inch: Final = 0.0254 +foot: Final = 0.3048 +yard: Final = 0.9144 +mile: Final = 1_609.344 +mil: Final = 2.54e-5 +pt: Final = 3.527777777777778e-4 +point: Final = 3.527777777777778e-4 +survey_foot: Final = 0.3048006096012192 +survey_mile: Final = 1_609.3472186944373 +nautical_mile: Final = 1_852.0 +fermi: Final = 1e-15 +angstrom: Final = 1e-10 +micron: Final = 1e-6 +au: Final = 149_597_870_700.0 +astronomical_unit: Final = 149_597_870_700.0 +light_year: Final = 9.460730472580800e15 +parsec: Final = 3.085677581491367e16 # pressure in pascal -atm: float -atmosphere: float -bar: float -torr: float -mmHg: float -psi: float +bar: Final = 100_000.0 +atm: Final = 101_325.0 +atmosphere: Final = 101_325.0 +torr: Final = 133.32236842105263 +mmHg: Final = 133.32236842105263 +psi: Final = 6_894.757293168361 # area in meter**2 -hectare: float -acre: float +hectare: Final = 10_000.0 +acre: Final = 4_046.8564224 # volume in meter**3 -litre: float -liter: float -gallon: float -gallon_US: float -fluid_ounce: float -fluid_ounce_US: float -bbl: float -barrel: float - -gallon_imp: float -fluid_ounce_imp: float +litre: Final = 1e-3 +liter: Final = 1e-3 +gallon: Final = 3.785411784e-3 +gallon_US: Final = 3.785411784e-3 +fluid_ounce: Final = 2.95735295625e-5 +fluid_ounce_US: Final = 2.95735295625e-5 +bbl: Final = 0.158987294928 +barrel: Final = 0.158987294928 +gallon_imp: Final = 4.54609e-3 +fluid_ounce_imp: Final = 2.84130625e-5 # speed in meter per second -kmh: float -mph: float -mach: float -speed_of_sound: float -knot: float +kmh: Final = 0.27777777777777777 +mph: Final = 0.44704 +mach: Final = 340.5 +speed_of_sound: Final = 340.5 +knot: Final = 0.5144444444444444 # temperature in kelvin -zero_Celsius: float -degree_Fahrenheit: float +zero_Celsius: Final = 273.15 +degree_Fahrenheit: Final = 0.55555555555555555 # energy in joule -eV = elementary_charge -electron_volt = elementary_charge -calorie: float -calorie_th: float -calorie_IT: float -erg: float -Btu_th: float -Btu: float -Btu_IT: float -ton_TNT: float +eV: Final = 1.602176634e-19 +electron_volt: Final = 1.602176634e-19 +calorie: Final = 4.184 +calorie_th: Final = 4.184 +calorie_IT: Final = 4.1868 +erg: Final = 1e-7 +Btu_th: Final = 1_054.3502644888888 +Btu: Final = 1_055.05585262 +Btu_IT: Final = 1_055.05585262 +ton_TNT: Final = 4.184e9 # power in watt -hp: float -horsepower: float +hp: Final = 745.6998715822701 +horsepower: Final = 745.6998715822701 # force in newton -dyn: float -dyne: float -lbf: float -pound_force: float -kgf = g -kilogram_force = g +dyn: Final = 1e-5 +dyne: Final = 1e-5 +lbf: Final = 4.4482216152605 +pound_force: Final = 4.4482216152605 +kgf: Final = 9.80665 +kilogram_force: Final = 9.80665 -def convert_temperature(val: npt.ArrayLike, old_scale: str, new_scale: str) -> np.float64 | npt.NDArray[np.float64]: ... -def lambda2nu(lambda_: npt.ArrayLike) -> np.float64 | npt.NDArray[np.float64]: ... -def nu2lambda(nu: npt.ArrayLike) -> np.float64 | npt.NDArray[np.float64]: ... +def convert_temperature( + val: _ArrayLikeFloat_co, + old_scale: _TempScale, + new_scale: _TempScale, +) -> np.float64 | npt.NDArray[np.float64]: ... +def lambda2nu(lambda_: _ArrayLikeFloat_co) -> np.float64 | npt.NDArray[np.float64]: ... +def nu2lambda(nu: _ArrayLikeFloat_co) -> np.float64 | npt.NDArray[np.float64]: ... diff --git a/scipy-stubs/constants/codata.pyi b/scipy-stubs/constants/codata.pyi new file mode 100644 index 00000000..ee5da77e --- /dev/null +++ b/scipy-stubs/constants/codata.pyi @@ -0,0 +1,4 @@ +# This file is not meant for public use and will be removed in SciPy v2.0.0. +from ._codata import ConstantWarning, c, find, k, physical_constants, precision, unit, value + +__all__ = ["ConstantWarning", "c", "find", "k", "physical_constants", "precision", "unit", "value"] diff --git a/scipy-stubs/constants/constants.pyi b/scipy-stubs/constants/constants.pyi new file mode 100644 index 00000000..8d18f11a --- /dev/null +++ b/scipy-stubs/constants/constants.pyi @@ -0,0 +1,314 @@ +# This file is not meant for public use and will be removed in SciPy v2.0.0. +from ._constants import ( + N_A, + Avogadro, + Boltzmann, + Btu, + Btu_IT, + Btu_th, + G, + Julian_year, + Planck, + R, + Rydberg, + Stefan_Boltzmann, + Wien, + acre, + alpha, + angstrom, + arcmin, + arcminute, + arcsec, + arcsecond, + astronomical_unit, + atm, + atmosphere, + atomic_mass, + atto, + au, + bar, + barrel, + bbl, + blob, + c, + calorie, + calorie_IT, + calorie_th, + carat, + centi, + convert_temperature, + day, + deci, + degree, + degree_Fahrenheit, + deka, + dyn, + dyne, + e, + electron_mass, + electron_volt, + elementary_charge, + epsilon_0, + erg, + eV, + exa, + exbi, + femto, + fermi, + fine_structure, + fluid_ounce, + fluid_ounce_imp, + fluid_ounce_US, + foot, + g, + gallon, + gallon_imp, + gallon_US, + gas_constant, + gibi, + giga, + golden, + golden_ratio, + grain, + gram, + gravitational_constant, + h, + hbar, + hectare, + hecto, + horsepower, + hour, + hp, + inch, + k, + kgf, + kibi, + kilo, + kilogram_force, + kmh, + knot, + lambda2nu, + lb, + lbf, + light_year, + liter, + litre, + long_ton, + m_e, + m_n, + m_p, + m_u, + mach, + mebi, + mega, + metric_ton, + micro, + micron, + mil, + mile, + milli, + minute, + mmHg, + mph, + mu_0, + nano, + nautical_mile, + neutron_mass, + nu2lambda, + ounce, + oz, + parsec, + pebi, + peta, + pi, + pico, + point, + pound, + pound_force, + proton_mass, + psi, + pt, + short_ton, + sigma, + slinch, + slug, + speed_of_light, + speed_of_sound, + stone, + survey_foot, + survey_mile, + tebi, + tera, + ton_TNT, + torr, + troy_ounce, + troy_pound, + u, + week, + yard, + year, + yobi, + yocto, + yotta, + zebi, + zepto, + zero_Celsius, + zetta, +) + +__all__ = [ + "N_A", + "Avogadro", + "Boltzmann", + "Btu", + "Btu_IT", + "Btu_th", + "G", + "Julian_year", + "Planck", + "R", + "Rydberg", + "Stefan_Boltzmann", + "Wien", + "acre", + "alpha", + "angstrom", + "arcmin", + "arcminute", + "arcsec", + "arcsecond", + "astronomical_unit", + "atm", + "atmosphere", + "atomic_mass", + "atto", + "au", + "bar", + "barrel", + "bbl", + "blob", + "c", + "calorie", + "calorie_IT", + "calorie_th", + "carat", + "centi", + "convert_temperature", + "day", + "deci", + "degree", + "degree_Fahrenheit", + "deka", + "dyn", + "dyne", + "e", + "eV", + "electron_mass", + "electron_volt", + "elementary_charge", + "epsilon_0", + "erg", + "exa", + "exbi", + "femto", + "fermi", + "fine_structure", + "fluid_ounce", + "fluid_ounce_US", + "fluid_ounce_imp", + "foot", + "g", + "gallon", + "gallon_US", + "gallon_imp", + "gas_constant", + "gibi", + "giga", + "golden", + "golden_ratio", + "grain", + "gram", + "gravitational_constant", + "h", + "hbar", + "hectare", + "hecto", + "horsepower", + "hour", + "hp", + "inch", + "k", + "kgf", + "kibi", + "kilo", + "kilogram_force", + "kmh", + "knot", + "lambda2nu", + "lb", + "lbf", + "light_year", + "liter", + "litre", + "long_ton", + "m_e", + "m_n", + "m_p", + "m_u", + "mach", + "mebi", + "mega", + "metric_ton", + "micro", + "micron", + "mil", + "mile", + "milli", + "minute", + "mmHg", + "mph", + "mu_0", + "nano", + "nautical_mile", + "neutron_mass", + "nu2lambda", + "ounce", + "oz", + "parsec", + "pebi", + "peta", + "pi", + "pico", + "point", + "pound", + "pound_force", + "proton_mass", + "psi", + "pt", + "short_ton", + "sigma", + "slinch", + "slug", + "speed_of_light", + "speed_of_sound", + "stone", + "survey_foot", + "survey_mile", + "tebi", + "tera", + "ton_TNT", + "torr", + "troy_ounce", + "troy_pound", + "u", + "week", + "yard", + "year", + "yobi", + "yocto", + "yotta", + "zebi", + "zepto", + "zero_Celsius", + "zetta", +] diff --git a/tests/stubtest/allowlist.txt b/tests/stubtest/allowlist.txt index a331e670..1740f1e6 100644 --- a/tests/stubtest/allowlist.txt +++ b/tests/stubtest/allowlist.txt @@ -77,15 +77,6 @@ scipy.special.libsf_error_state scipy.stats._rcont.rcont scipy.stats._unuran.unuran_wrapper -# deprecated public api (will be removed in scipy 2.0.0) -scipy.constants.codata -scipy.constants.constants -scipy.stats.kde.* -scipy.stats.morestats.* -scipy.stats.mstats_basic.* -scipy.stats.mstats_extras.* -scipy.stats.stats.* - # mypy hallucinations scipy._lib._ccallback.PyCFuncPtr # `final(T)` is impossible scipy.integrate._quadrature.QMCQuadResult.__replace__ # bruh... @@ -93,15 +84,10 @@ scipy.interpolate.AAA scipy.interpolate._aaa scipy.interpolate._interpnd_info -# deprecated submodules are removed from these `__all__` -scipy.constants.__all__ -scipy.stats.__all__ - -# TODO +# TODO: scipy._lib._ccallback.__all__ scipy._lib.array_api_compat.__all__ scipy._lib.array_api_compat.common.__all__ -scipy.signal._signaltools.__all__ scipy.sparse._matrix.__all__ scipy.sparse.csgraph.__all__ scipy.sparse.csgraph._flow.__all__ @@ -119,6 +105,7 @@ scipy.spatial.kdtree.__all__ scipy.spatial.qhull.__all__ scipy.spatial.transform._rotation.__all__ scipy.spatial.transform._rotation_spline.__all__ +scipy.stats.__all__ scipy.stats._binomtest.__all__ scipy.stats._bws_test.__all__ scipy.stats._censored_data.__all__ @@ -129,3 +116,8 @@ scipy.stats._distn_infrastructure.__all__ scipy.stats._distr_params.__all__ scipy.stats.distributions.__all__ scipy.stats.sampling.__all__ +scipy.stats.kde.* +scipy.stats.morestats.* +scipy.stats.mstats_basic.* +scipy.stats.mstats_extras.* +scipy.stats.stats.*