<commit_before>import os
import sys
import glob
import datetime

import numpy

import arcpy


def progress_print(msg, verbose=False, asMessage=False):
    if verbose:
        if asMessage:
            arcpy.AddMessage(msg)
        else:
            print(msg)


class EasyMapDoc(object):
    def __init__(self, *args, **kwargs):
        self.mapdoc = arcpy.mapping.MapDocument(*args, **kwargs)

    @property
    def layers(self):
        return arcpy.mapping.ListLayers(self.mapdoc)

    @property
    def dataframes(self):
        return arcpy.mapping.ListDataFrames(self.mapdoc)

    def findLayerByName(self, name):
        for lyr in self.layers:
            if not lyr.isGroupLayer and lyr.name == name:
                return lyr

    def add_layer(self, layer, df=None, position='top'):
        # if no dataframe is provided, select the first
        if df is None:
            df = self.dataframes[0]

        # check that the position is valid
        valid_positions = ['auto_arrange', 'bottom', 'top']
        if position.lower() not in valid_positions:
            raise ValueError('Position: %s is not in %s' % (position.lower, valid_positions))

        # layer can be a path to a file. if so, convert to a Layer object<commit_msg>add case where the opening the mapdoc fails<commit_after>import os
import sys
import glob
import datetime

import numpy

import arcpy


def progress_print(msg, verbose=False, asMessage=False):
    if verbose:
        if asMessage:
            arcpy.AddMessage(msg)
        else:
            print(msg)


class EasyMapDoc(object):
    def __init__(self, *args, **kwargs):
        try:
            self.mapdoc = arcpy.mapping.MapDocument(*args, **kwargs)
        except RuntimeError:
            self.mapdoc = None

    @property
    def layers(self):
        return arcpy.mapping.ListLayers(self.mapdoc)

    @property
    def dataframes(self):
        return arcpy.mapping.ListDataFrames(self.mapdoc)

    def findLayerByName(self, name):
        for lyr in self.layers:
            if not lyr.isGroupLayer and lyr.name == name:
                return lyr

    def add_layer(self, layer, df=None, position='top'):
        # if no dataframe is provided, select the first
        if df is None:
            df = self.dataframes[0]

        # check that the position is valid
        valid_positions = ['auto_arrange', 'bottom', 'top']
        if position.lower() not in valid_positions:
            raise ValueError('Position: %s is not in %s' % (position.lower, valid_positions))

        # layer can be a path to a file. if so, convert to a Layer object
{'fraction_non_alphanumeric': 0.0908041554444017, 'fraction_numerical': 0.0007695267410542517, 'mean_word_length': 2.4346103038309117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5788122', 'n_tokens_mistral': 773, 'n_tokens_neox': 742, 'n_words': 241}