iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >pandas关于查看库或依赖库版本的API原理是什么
  • 832
分享到

pandas关于查看库或依赖库版本的API原理是什么

2023-07-02 10:07:20 832人浏览 安东尼
摘要

今天小编给大家分享一下pandas关于查看库或依赖库版本的api原理是什么的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。概述

今天小编给大家分享一下pandas关于查看库或依赖库版本的api原理是什么的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

概述

pandas中与库版本或依赖库版本相关的API主要有以下4个:

  • pandas.__version__:查看pandas简要版本信息。

  • pandas.__git_version__:查看pandasgit版本信息。

  • pandas._version.get_versions():查看pandas详细版本信息。

  • pandas.show_versions():查看pandas及其依赖库的版本信息。

上述API的运行效果如下:

In [1]: import pandas as pd

In [2]: pd.__version__
Out[2]: '1.1.3'

In [3]: pd.__git_version__
Out[3]: 'db08276bc116c438d3fdee492026f8223584c477'

In [4]: pd._version.get_versions()
Out[4]:
{'dirty': False,
 'error': None,
 'full-revisionid': 'db08276bc116c438d3fdee492026f8223584c477',
 'version': '1.1.3'}

In [5]: pd.show_versions(True)
{'system': {'commit': 'db08276bc116c438d3fdee492026f8223584c477', 'python': '3.7.2.final.0', 'Python-bits': 64, 'OS': 'windows', 'OS-release': '10', 'Version': '10.0.17763', 'Machine': 'AMD64', 'processor': 'Intel64 Family 6 Model 94 Stepping 3, GenuineIntel', 'byteorder': 'little', 'LC_ALL': None, 'LANG': None, 'LOCALE': {'language-code': None, 'encoding': None}}, 'dependencies': {'pandas': '1.1.3', 'numpy': '1.20.1', 'pytz': '2019.2', 'dateutil': '2.8.0', 'pip': '19.3.1', 'setuptools': '51.1.0.post20201221', 'Cython': None, 'pytest': None, 'hypothesis': None, 'sphinx': None, 'blosc': None, 'feather': None, 'xlsxwriter': '3.0.1', 'lxml.etree': '4.4.2', 'HTML5lib': '1.1', 'pymysql': '0.9.3', 'psycopg2': None, 'jinja2': '2.11.2', 'IPython': '7.11.1', 'pandas_datareader': None, 'bs4': '4.9.3', 'bottleneck': None, 'fsspec': None, 'fastparquet': None, 'GCsfs': None, 'matplotlib': '3.4.1', 'numexpr': None, 'odfpy': None, 'openpyxl': '2.6.2', 'pandas_gbq': None, 'pyarrow': None, 'pytables': None, 'pyxlsb': None, 's3fs': None, 'scipy': '1.2.1', 'sqlalchemy': '1.4.18', 'tables': None, 'tabulate': None, 'xarray': None, 'xlrd': '1.2.0', 'xlwt': '1.3.0', 'numba': '0.52.0'}}

pandas._version.get_versions()、pandas.__version__和pandas.__git_version__原理

pandas._version.get_versions()

pandas._version.get_versions()源代码位于pandas包根目录下的_version.py。根据源码可知,该模块以JSON字符串形式存储版本信息,通过get_versions()返回字典形式的详细版本信息。

pandas/_version.py源码

from warnings import catch_warningswith catch_warnings(record=True):    import jsonimport sysversion_json = '''{ "dirty": false, "error": null, "full-revisionid": "db08276bc116c438d3fdee492026f8223584c477", "version": "1.1.3"}'''  # END VERSION_JSONdef get_versions():    return json.loads(version_json)

pandas.__version__pandas.__git_version__

pandas.__version__pandas.__git_version__源代码位于pandas包根目录下的__init__.py。根据源码可知,pandas.__version__pandas.__git_version__源自于pandas._version.get_versions()的返回值。

生成这两个之后,删除了get_versionsv两个命名空间,因此不能使用pandas.get_versions()pandas.v形式查看版本信息。

相关源码:

from ._version import get_versionsv = get_versions()__version__ = v.get("closest-tag", v["version"])__git_version__ = v.get("full-revisionid")del get_versions, v

pandas.show_versions()原理

根据pandas包根目录下的__init__.py源码可知,通过from pandas.util._print_versions import show_versions重构命名空间,pandas.show_versions()的源代码位于pandasutil目录下的_print_versions.py模块。

根据源码可知,pandas.show_versions()的参数取值有3种情况:

  • False:打印输出类表格形式的依赖库版本信息。

  • True:打印输出JSON字符串形式的依赖库版本信息。

  • 字符串:参数被认为是文件路径,版本信息以JSON形式写入该文件。

注意!pandas.show_versions()没有返回值即None

pandas.show_versions()不同参数输出结果

In [5]: pd.show_versions(True){'system': {'commit': 'db08276bc116c438d3fdee492026f8223584c477', 'python': '3.7.2.final.0', 'python-bits': 64, 'OS': 'Windows', 'OS-release': '10', 'Version': '10.0.17763', 'machine': 'AMD64', 'processor': 'Intel64 Family 6 Model 94 Stepping 3, GenuineIntel', 'byteorder': 'little', 'LC_ALL': None, 'LANG': None, 'LOCALE': {'language-code': None, 'encoding': None}}, 'dependencies': {'pandas': '1.1.3', 'numpy': '1.20.1', 'pytz': '2019.2', 'dateutil': '2.8.0', 'pip': '19.3.1', 'setuptools': '51.1.0.post20201221', 'Cython': None, 'pytest': None, 'hypothesis': None, 'sphinx': None, 'blosc': None, 'feather': None, 'xlsxwriter': '3.0.1', 'lxml.etree': '4.4.2', 'html5lib': '1.1', 'pyMysql': '0.9.3', 'psycopg2': None, 'jinja2': '2.11.2', 'IPython': '7.11.1', 'pandas_datareader': None, 'bs4': '4.9.3', 'bottleneck': None, 'fsspec': None, 'fastparquet': None, 'gcsfs': None, 'matplotlib': '3.4.1', 'numexpr': None, 'odfpy': None, 'openpyxl': '2.6.2', 'pandas_gbq': None, 'pyarrow': None, 'pytables': None, 'pyxlsb': None, 's3fs': None, 'scipy': '1.2.1', 'sqlalchemy': '1.4.18', 'tables': None, 'tabulate': None, 'xarray': None, 'xlrd': '1.2.0', 'xlwt': '1.3.0', 'numba': '0.52.0'}}In [6]: pd.show_versions()INSTALLED VERSIONS------------------commit           : db08276bc116c438d3fdee492026f8223584c477python           : 3.7.2.final.0python-bits      : 64OS               : WindowsOS-release       : 10Version          : 10.0.17763machine          : AMD64processor        : Intel64 Family 6 Model 94 Stepping 3, GenuineIntelbyteorder        : littleLC_ALL           : NoneLANG             : NoneLOCALE           : None.Nonepandas           : 1.1.3numpy            : 1.20.1pytz             : 2019.2dateutil         : 2.8.0pip              : 19.3.1setuptools       : 51.1.0.post20201221Cython           : Nonepytest           : Nonehypothesis       : Nonesphinx           : Noneblosc            : Nonefeather          : Nonexlsxwriter       : 3.0.1lxml.etree       : 4.4.2html5lib         : 1.1pymysql          : 0.9.3psycopg2         : Nonejinja2           : 2.11.2IPython          : 7.11.1pandas_datareader: Nonebs4              : 4.9.3bottleneck       : Nonefsspec           : Nonefastparquet      : Nonegcsfs            : Nonematplotlib       : 3.4.1numexpr          : Noneodfpy            : Noneopenpyxl         : 2.6.2pandas_gbq       : Nonepyarrow          : Nonepytables         : Nonepyxlsb           : Nones3fs             : Nonescipy            : 1.2.1sqlalchemy       : 1.4.18tables           : Nonetabulate         : Nonexarray           : Nonexlrd             : 1.2.0xlwt             : 1.3.0numba            : 0.52.0In [7]: pd.show_versions("./version.json")

pandas关于查看库或依赖库版本的API原理是什么

相关源码:

def show_versions(as_json: UNIOn[str, bool] = False) -> None:    """    Provide useful infORMation, important for bug reports.    It comprises info about hosting operation system, pandas version,    and versions of other installed relative packages.    Parameters    ----------    as_json : str or bool, default False        * If False, outputs info in a human readable form to the console.        * If str, it will be considered as a path to a file.          Info will be written to that file in JSON format.        * If True, outputs info in JSON format to the console.    """    sys_info = _get_sys_info()    deps = _get_dependency_info()    if as_json:        j = dict(system=sys_info, dependencies=deps)        if as_json is True:            print(j)        else:            assert isinstance(as_json, str)  # needed for mypy            with codecs.open(as_json, "wb", encoding="utf8") as f:                json.dump(j, f, indent=2)    else:        assert isinstance(sys_info["LOCALE"], dict)  # needed for mypy        language_code = sys_info["LOCALE"]["language-code"]        encoding = sys_info["LOCALE"]["encoding"]        sys_info["LOCALE"] = f"{language_code}.{encoding}"        maxlen = max(len(x) for x in deps)        print("\nINSTALLED VERSIONS")        print("------------------")        for k, v in sys_info.items():            print(f"{k:<{maxlen}}: {v}")        print("")        for k, v in deps.items():            print(f"{k:<{maxlen}}: {v}")

以上就是“pandas关于查看库或依赖库版本的API原理是什么”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注编程网精选频道。

--结束END--

本文标题: pandas关于查看库或依赖库版本的API原理是什么

本文链接: https://www.lsjlt.com/news/341261.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • pandas关于查看库或依赖库版本的API原理是什么
    今天小编给大家分享一下pandas关于查看库或依赖库版本的API原理是什么的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。概述...
    99+
    2023-07-02
  • 浅谈pandas关于查看库或依赖库版本的API原理
    概述 pandas中与库版本或依赖库版本相关的API主要有以下4个: pandas.__version__:查看pandas简要版本信息。pandas.__git_version__...
    99+
    2024-04-02
  • 怎么在基于Ubuntu或Debian的Linux 发行版中查看一个软件包的依赖
    这篇文章将为大家详细讲解有关怎么在基于Ubuntu或Debian的Linux 发行版中查看一个软件包的依赖,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。什么是 Ubuntu 中的包依赖?当你在 Linux...
    99+
    2023-06-15
  • sqlserver数据库高版本备份还原为低版本的方法是什么
    今天就跟大家聊聊有关sqlserver数据库高版本备份还原为低版本的方法是什么,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。问题描述:高版本sql备...
    99+
    2024-04-02
  • 关系型数据库的原理及优势是什么
    这期内容当中小编将会给大家带来有关关系型数据库的原理及优势是什么,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。无论我们接触什么程序语言,都会使用到数据库,提起数据库,我们...
    99+
    2024-04-02
  • SymPy库关于矩阵的基本操作和运算方法是什么
    这篇“SymPy库关于矩阵的基本操作和运算方法是什么”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“SymPy库关于矩阵的基本...
    99+
    2023-07-05
  • Vue中计算属性、监听属性、数据的响应式更新和依赖收集基本原理是什么
    这篇文章主要介绍“Vue中计算属性、监听属性、数据的响应式更新和依赖收集基本原理是什么”,在日常操作中,相信很多人在Vue中计算属性、监听属性、数据的响应式更新和依赖收集基本原理是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作...
    99+
    2023-07-05
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作