欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

淺談pandas關(guān)于查看庫(kù)或依賴(lài)庫(kù)版本的API原理

 更新時(shí)間:2022年06月17日 09:38:57   作者:mighty13  
本文主要介紹了淺談pandas關(guān)于查看庫(kù)或依賴(lài)庫(kù)版本的API原理,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

概述

pandas中與庫(kù)版本或依賴(lài)庫(kù)版本相關(guān)的API主要有以下4個(gè):

  • pandas.__version__:查看pandas簡(jiǎn)要版本信息。
  • pandas.__git_version__:查看pandasgit版本信息。
  • pandas._version.get_versions():查看pandas詳細(xì)版本信息。
  • pandas.show_versions():查看pandas及其依賴(lài)庫(kù)的版本信息。

上述API的運(yùn)行效果如下:

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。根據(jù)源碼可知,該模塊以JSON字符串形式存儲(chǔ)版本信息,通過(guò)get_versions()返回字典形式的詳細(xì)版本信息。

pandas/_version.py源碼

from warnings import catch_warnings
with catch_warnings(record=True):
    import json
import sys

version_json = '''
{
 "dirty": false,
 "error": null,
 "full-revisionid": "db08276bc116c438d3fdee492026f8223584c477",
 "version": "1.1.3"
}
'''  # END VERSION_JSON


def get_versions():
    return json.loads(version_json)

pandas.__version__pandas.__git_version__

pandas.__version__pandas.__git_version__源代碼位于pandas包根目錄下的__init__.py。根據(jù)源碼可知,pandas.__version__pandas.__git_version__源自于pandas._version.get_versions()的返回值。

生成這兩個(gè)之后,刪除了get_versions、v兩個(gè)命名空間,因此不能使用pandas.get_versions()pandas.v形式查看版本信息。

相關(guān)源碼:

from ._version import get_versions

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

pandas.show_versions()原理

根據(jù)pandas包根目錄下的__init__.py源碼可知,通過(guò)from pandas.util._print_versions import show_versions重構(gòu)命名空間,pandas.show_versions()的源代碼位于pandasutil目錄下的_print_versions.py模塊。

根據(jù)源碼可知,pandas.show_versions()的參數(shù)取值有3種情況:

  • False:打印輸出類(lèi)表格形式的依賴(lài)庫(kù)版本信息。
  • True:打印輸出JSON字符串形式的依賴(lài)庫(kù)版本信息。
  • 字符串:參數(shù)被認(rèn)為是文件路徑,版本信息以JSON形式寫(xiě)入該文件。

注意!pandas.show_versions()沒(méi)有返回值即None。

pandas.show_versions()不同參數(shù)輸出結(jié)果

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           : 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           : None.None

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 [7]: pd.show_versions("./version.json")

在這里插入圖片描述

相關(guān)源碼:

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}")

到此這篇關(guān)于淺談pandas關(guān)于查看庫(kù)或依賴(lài)庫(kù)版本的API原理的文章就介紹到這了,更多相關(guān)pandas 依賴(lài)庫(kù)API內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python實(shí)現(xiàn)棧的方法詳解【基于數(shù)組和單鏈表兩種方法】

    Python實(shí)現(xiàn)棧的方法詳解【基于數(shù)組和單鏈表兩種方法】

    這篇文章主要介紹了Python實(shí)現(xiàn)棧的方法,結(jié)合實(shí)例形式詳細(xì)分析了Python基于數(shù)組和單鏈表兩種方法定義棧的相關(guān)操作技巧,需要的朋友可以參考下
    2020-02-02
  • yolov5中anchors設(shè)置實(shí)例詳解

    yolov5中anchors設(shè)置實(shí)例詳解

    在YOLOV5算法之中,針對(duì)不同的數(shù)據(jù)集,一般會(huì)預(yù)先設(shè)置固定的Anchor,下面這篇文章主要給大家介紹了關(guān)于yolov5中anchors設(shè)置的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • Python中表格插件Tabulate的用法小結(jié)

    Python中表格插件Tabulate的用法小結(jié)

    這篇文章主要介紹了Python中表格插件Tabulate的用法,Tabulate插件是一個(gè)功能強(qiáng)大、簡(jiǎn)單易用的數(shù)據(jù)可視化工具,它能夠滿(mǎn)足我們?cè)赑ython中進(jìn)行表格數(shù)據(jù)展示的各種需求,通過(guò)使用Tabulate插件,我們能夠輕松地生成美觀且易讀的表格,需要的朋友可以參考下
    2023-11-11
  • Python實(shí)現(xiàn)識(shí)別XSS漏洞的方法詳解

    Python實(shí)現(xiàn)識(shí)別XSS漏洞的方法詳解

    XSS(跨站腳本攻擊)作為一種常見(jiàn)的網(wǎng)絡(luò)安全漏洞,經(jīng)常被黑客用來(lái)攻擊網(wǎng)站。這篇文章主要介紹了如何利用Python 識(shí)別 XSS 漏洞,需要的可以參考一下
    2023-02-02
  • Python使用Selenium WebDriver的入門(mén)介紹及安裝教程(最新推薦)

    Python使用Selenium WebDriver的入門(mén)介紹及安裝教程(最新推薦)

    這篇文章主要介紹了Python使用Selenium WebDriver的入門(mén)介紹及安裝教程,本文使用環(huán)境為python3.11+win10 64位+firefox瀏覽器,所以本文使用的瀏覽器驅(qū)動(dòng)是Firefox的geckodriver ,如果你使用的是其他瀏覽器,那么選擇自己對(duì)應(yīng)的瀏覽器驅(qū)動(dòng)程序即可,需要的朋友可以參考下
    2023-04-04
  • python的getattr和getattribute攔截內(nèi)置操作實(shí)現(xiàn)

    python的getattr和getattribute攔截內(nèi)置操作實(shí)現(xiàn)

    在Python中,getattr和getattribute是用于動(dòng)態(tài)屬性訪(fǎng)問(wèn)和自定義屬性訪(fǎng)問(wèn)行為的重要工具,本文主要介紹了python的getattr和getattribute攔截內(nèi)置操作實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-01-01
  • ubuntu系統(tǒng)下 python鏈接mysql數(shù)據(jù)庫(kù)的方法

    ubuntu系統(tǒng)下 python鏈接mysql數(shù)據(jù)庫(kù)的方法

    這篇文章主要介紹了ubuntu系統(tǒng)下 python鏈接mysql數(shù)據(jù)庫(kù)的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-01-01
  • 簡(jiǎn)單實(shí)現(xiàn)python爬蟲(chóng)功能

    簡(jiǎn)單實(shí)現(xiàn)python爬蟲(chóng)功能

    這篇文章主要介紹了python實(shí)現(xiàn)簡(jiǎn)單爬蟲(chóng)功能的相關(guān)資料,感興趣的小伙伴們可以參考一下
    2015-12-12
  • python實(shí)現(xiàn)簡(jiǎn)單socket通信的方法

    python實(shí)現(xiàn)簡(jiǎn)單socket通信的方法

    這篇文章主要介紹了python實(shí)現(xiàn)簡(jiǎn)單socket通信的方法,結(jié)合實(shí)例形式分析了socket通信服務(wù)端與客戶(hù)端的具體實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-04-04
  • python每隔N秒運(yùn)行指定函數(shù)的方法

    python每隔N秒運(yùn)行指定函數(shù)的方法

    這篇文章主要介紹了python每隔N秒運(yùn)行指定函數(shù)的方法,涉及Python的線(xiàn)程與時(shí)間操作技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-03-03

最新評(píng)論