最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

概述

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

  • pandas.__version__:查看pandas簡要版本信息。
  • pandas.__git_version__:查看pandasgit版本信息。
  • pandas._version.get_versions():查看pandas詳細(xì)版本信息。
  • pandas.show_versions():查看pandas及其依賴庫的版本信息。

上述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字符串形式存儲版本信息,通過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_versionsv兩個(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源碼可知,通過from pandas.util._print_versions import show_versions重構(gòu)命名空間,pandas.show_versions()的源代碼位于pandasutil目錄下的_print_versions.py模塊。

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

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

注意!pandas.show_versions()沒有返回值即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)于查看庫或依賴庫版本的API原理的文章就介紹到這了,更多相關(guān)pandas 依賴庫API內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python的依賴管理的實(shí)現(xiàn)

    python的依賴管理的實(shí)現(xiàn)

    這篇文章主要介紹了python的依賴管理的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • np.zeros()函數(shù)的使用方法

    np.zeros()函數(shù)的使用方法

    本文主要介紹了np.zeros()函數(shù)的使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • python-httpx的使用及說明

    python-httpx的使用及說明

    這篇文章主要介紹了python-httpx的使用及說明,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • Flask中Cookie和Session理解與作用介紹

    Flask中Cookie和Session理解與作用介紹

    Flask是一個(gè)使用 Python 編寫的輕量級 Web 應(yīng)用框架。其 WSGI 工具箱采用 Werkzeug ,模板引擎則使用 Jinja2 。Flask使用 BSD 授權(quán)。Flask也被稱為 “microframework” ,因?yàn)樗褂煤唵蔚暮诵?,?nbsp;extension 增加其他功能,F(xiàn)lask中Cookie和Session有什么區(qū)別呢
    2022-10-10
  • Python操作Word批量生成文章的方法

    Python操作Word批量生成文章的方法

    這篇文章主要介紹了Python操作Word批量生成文章的方法,需要的朋友可以參考下
    2015-07-07
  • pytorch masked_fill報(bào)錯的解決

    pytorch masked_fill報(bào)錯的解決

    今天小編就為大家分享一篇pytorch masked_fill報(bào)錯的解決,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02
  • python如何壓縮新文件到已有ZIP文件

    python如何壓縮新文件到已有ZIP文件

    這篇文章主要為大家詳細(xì)介紹了python如何壓縮新文件到已有ZIP文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • Python 實(shí)用技巧之利用Shell通配符做字符串匹配

    Python 實(shí)用技巧之利用Shell通配符做字符串匹配

    這篇文章主要介紹了Python 實(shí)用技巧之利用Shell通配符做字符串匹配的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-08-08
  • Python中def()函數(shù)的實(shí)戰(zhàn)練習(xí)題

    Python中def()函數(shù)的實(shí)戰(zhàn)練習(xí)題

    def是define的縮寫,用來自定義函數(shù),下面這篇文章主要給大家介紹了關(guān)于Python中def()函數(shù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-07-07
  • Django框架自定義模型管理器與元選項(xiàng)用法分析

    Django框架自定義模型管理器與元選項(xiàng)用法分析

    這篇文章主要介紹了Django框架自定義模型管理器與元選項(xiàng)用法,結(jié)合實(shí)例形式分析了自定義模型管理器與元選項(xiàng)的功能、用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下
    2019-07-07

最新評論

麻城市| 阿勒泰市| 建始县| 井冈山市| 天祝| 长阳| 农安县| 苍山县| 钟山县| 仁布县| 姜堰市| 莱芜市| 岐山县| 哈密市| 澎湖县| 麦盖提县| 凤山县| 平和县| 合江县| 洛川县| 武邑县| 蒙山县| 化德县| 彭山县| 平陆县| 永顺县| 博爱县| 河源市| 凤翔县| 汶川县| 和田县| 华蓥市| 汝南县| 宿松县| 安徽省| 怀集县| 乌兰察布市| 慈利县| 湖州市| 康保县| 攀枝花市|