ネタ元:
- 奥村晴彦 / Python / 2020-12-27: xlrd が xlsx に対応しなくなった
2020-11-11 リリースの xlrd ver2.0.0 にて
従来 pandas の read_excel() 関数では engine=None だとデフォルトで xlrd が用いられ、これは .xls, .xlsx の両方が読めていたのに、xlrd 2.0.0 以降を入れた環境では上記の変更の影響で、xlrd では .xlsx が読めなくなったとの事。
これを受けて、2020-12-26 リリースの pandas version 1.2.0 では、read_excel () の振る舞いが以下のように変更されたので、とりあえず pandas 1.2 以上に上げておけば問題は解決する模様。
詳細は以下を参照
- Remove support for anything other than .xls files.
従来 pandas の read_excel() 関数では engine=None だとデフォルトで xlrd が用いられ、これは .xls, .xlsx の両方が読めていたのに、xlrd 2.0.0 以降を入れた環境では上記の変更の影響で、xlrd では .xlsx が読めなくなったとの事。
これを受けて、2020-12-26 リリースの pandas version 1.2.0 では、read_excel () の振る舞いが以下のように変更されたので、とりあえず pandas 1.2 以上に上げておけば問題は解決する模様。
enginestr, default None If io is not a buffer or path, this must be set to identify io. Supported engines: “xlrd”, “openpyxl”, “odf”, “pyxlsb”. Engine compatibility : ・“xlrd” supports old-style Excel files (.xls). ・“openpyxl” supports newer Excel file formats. ・“odf” supports OpenDocument file formats (.odf, .ods, .odt). ・“pyxlsb” supports Binary Excel files. Changed in version 1.2.0: The engine xlrd now only supports old-style .xls files. When engine=None, the following logic will be used to determine the engine: ・If path_or_buffer is an OpenDocument format (.odf, .ods, .odt), then odf will be used. ・Otherwise if path_or_buffer is an xls format, xlrd will be used. ・Otherwise if openpyxl is installed, then openpyxl will be used. ・Otherwise if xlrd >= 2.0 is installed, a ValueError will be raised. ・Otherwise xlrd will be used and a FutureWarning will be raised. This case will raise a ValueError in a future version of pandas.
詳細は以下を参照
- Pandas
- Release notes / 2020-12-26: What’s new in 1.2.0 (December 26, 2020)
- API reference
- version 1.2 / read_excel()
- version 1.1 / read_excel()
Ubuntu 20.04.1 LTS の公式パッケージは以下のような状況なので、今の所直接的な影響はない。
現状だと
20.10 (groovy) は なので問題なし。
本日 2020-12-27 時点の hirsute (21.04 ?) を見る限りでは に上がる予定のようなので、こちらも現時点では問題なし。
今後収録バージョンが上がると問題が発生する可能性はゼロではないがおそらく大丈夫だろう。
あと、odf は pandas の依存関係に入ってないようなので別途導入が必要。
って、read_excel() で ODF 読めるのも不思議な話だが、Excel も ODF サポートしてるので、読めないよりは読めたほうが利便性高いよね。
$ dpkg -l | grep -E 'python3-(pandas|xlrd|xlwt|openpyxl|odf) ' | sed -E 's/ +/\t/g' | column -t -s $'\t' ii python3-odf 1.4.0-3 all Python3 API to manipulate OpenDocument files ii python3-openpyxl 3.0.3-1 all Python 3 module to read/write OpenXML xlsx/xlsm files ii python3-pandas 0.25.3+dfsg-7 all data structures for "relational" or "labeled" data ii python3-xlrd 1.1.0-5 all extract data from Microsoft Excel spreadsheet files (Python3 version) ii python3-xlwt 1.3.0-3 all module for writing Microsoft Excel spreadsheet files - Python 3.x20.04 LTS (focal)では pandas 0.25 の依存関係には xlrd, xlwt, openpyxl が入ってるので、将来的に pandas 0.25.3 超 1.2 未満かつ xlrd 2.0.0 以上に変更されない限りは、この問題を踏むことは無いはず。
現状だと
20.10 (groovy) は なので問題なし。
本日 2020-12-27 時点の hirsute (21.04 ?) を見る限りでは に上がる予定のようなので、こちらも現時点では問題なし。
今後収録バージョンが上がると問題が発生する可能性はゼロではないがおそらく大丈夫だろう。
あと、odf は pandas の依存関係に入ってないようなので別途導入が必要。
って、read_excel() で ODF 読めるのも不思議な話だが、Excel も ODF サポートしてるので、読めないよりは読めたほうが利便性高いよね。
タグ
コメントをかく