Python 3: make decoding shapefile fields more lenient...

オープン
#187 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
data

調査の方向性

shapefile.py の Python 3 用フィールドデコードヘルパーから始め、リンク先の network.zip shape で失敗を再現します。デコードできない bytes を含むフィールドが shape の描画を妨げなくなっていることを確認し、既存の string および非 byte の処理が変わらず維持されていることも確認します。

索引モデルが issue の本文から書いたものです。

説明

In python 3, field values of shapefile are parsed in shapefile.py, as shown below:

def u(v):
    if PYTHON3:
        if isinstance(v, bytes):
            # For python 3 decode bytes to str.
            return v.decode('utf-8')
        elif isinstance(v, str):
            # Already str.
            return v
        else:
            # Error.
            raise Exception('Unknown input type')
    else:
        # For python 2 assume str passed in and return str.
        return v

But in the case v.decode fails in the first if (when v is an instance of bytes), then the file won't be drawn. I propose to change it as follows (to make it work):

def u(v):
    if PYTHON3:
        if isinstance(v, bytes):
            # For python 3 decode bytes to str.
            return v.decode('utf-8', errors='ignore')
        elif isinstance(v, str):
            # Already str.
            return v
        else:
            # Error.
            raise Exception('Unknown input type')
    else:
        # For python 2 assume str passed in and return str.
        return v

Here is the link to the shape on which the original version fails and the changed one works:
https://dl.dropboxusercontent.com/u/4629759/network.zip

Cheers

主要言語
Python
スター
817
フォーク
395
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

matplotlib/basemap のほかの issue

matplotlib/basemap の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。