<commit_before>import io
import os.path
import sys
import zipfile

from six.moves.urllib.request import urlopen
from pandas.util.testing import assert_isinstance

from geopandas import GeoDataFrame, GeoSeries

HERE = os.path.abspath(os.path.dirname(__file__))
PACKAGE_DIR = os.path.dirname(os.path.dirname(HERE))

# Compatibility layer for Python 2.6: try loading unittest2
if sys.version_info[:2] == (2, 6):
    try:
        import unittest2 as unittest
    except ImportError:
        import unittest
else:
    import unittest

try:
    import psycopg2
    from psycopg2 import OperationalError
except ImportError:
    class OperationalError(Exception):
        pass

try:
    import unittest.mock as mock
except ImportError:
    import mock

try:
    from pandas import read_sql_table
except ImportError:
    PANDAS_NEW_SQL_API = False
else:
    PANDAS_NEW_SQL_API = True


def download_nybb():
    """ Returns the path to the NYC boroughs file. Downloads if necessary.

    returns tuple (zip file name, shapefile's name and path within zip file)"""
    # Data from http://www.nyc.gov/html/dcp/download/bytes/nybb_14aav.zip
    # saved as geopandas/examples/nybb_14aav.zip.
    filename = 'nybb_16a.zip'
    full_path_name = os.path.join(PACKAGE_DIR, 'examples', filename)
    if not os.path.exists(full_path_name):
        with io.open(full_path_name, 'wb') as f:
            response = urlopen('http://www1.nyc.gov/assets/planning/download/zip/data-maps/open-data/{0}'.format(filename))
            f.write(response.read())

    shp_zip_path = None
    zf = zipfile.ZipFile(full_path_name, 'r')
    # finds path name in zip file
    for zip_filename_path in zf.namelist():
        if zip_filename_path.endswith('nybb.shp'):
            break

    return full_path_name, ('/' + zip_filename_path)


def validate_boro_df(test, df):
    """ Tests a GeoDataFrame that has been read in from the nybb dataset."""<commit_msg>BUG: nybb zip file no longer exists. (#373)<commit_after>import io
import os.path
import sys
import zipfile

from six.moves.urllib.request import urlopen
from pandas.util.testing import assert_isinstance

from geopandas import GeoDataFrame, GeoSeries

HERE = os.path.abspath(os.path.dirname(__file__))
PACKAGE_DIR = os.path.dirname(os.path.dirname(HERE))

# Compatibility layer for Python 2.6: try loading unittest2
if sys.version_info[:2] == (2, 6):
    try:
        import unittest2 as unittest
    except ImportError:
        import unittest
else:
    import unittest

try:
    import psycopg2
    from psycopg2 import OperationalError
except ImportError:
    class OperationalError(Exception):
        pass

try:
    import unittest.mock as mock
except ImportError:
    import mock

try:
    from pandas import read_sql_table
except ImportError:
    PANDAS_NEW_SQL_API = False
else:
    PANDAS_NEW_SQL_API = True


def download_nybb():
    """ Returns the path to the NYC boroughs file. Downloads if necessary.

    returns tuple (zip file name, shapefile's name and path within zip file)"""
    # Data from http://www.nyc.gov/html/dcp/download/bytes/nybb_14aav.zip
    # saved as geopandas/examples/nybb_14aav.zip.
    filename = 'nybb_16a.zip'
    full_path_name = os.path.join(PACKAGE_DIR, 'examples', filename)
    if not os.path.exists(full_path_name):
        with io.open(full_path_name, 'wb') as f:
            response = urlopen('https://github.com/geopandas/geopandas/files/555970/{0}'.format(filename))
            f.write(response.read())

    shp_zip_path = None
    zf = zipfile.ZipFile(full_path_name, 'r')
    # finds path name in zip file
    for zip_filename_path in zf.namelist():
        if zip_filename_path.endswith('nybb.shp'):
            break

    return full_path_name, ('/' + zip_filename_path)


def validate_boro_df(test, df):
    """ Tests a GeoDataFrame that has been read in from the nybb dataset."""
{'fraction_non_alphanumeric': 0.09427609427609428, 'fraction_numerical': 0.010878010878010878, 'mean_word_length': 3.4699074074074074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5181151', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1262, 'n_words': 338}