<commit_before>import sys, copy, os, itertools
import time


import rpy2.robjects as robjects
import rpy2.rinterface as rinterface
from rpy2.robjects.vectors import SexpVector, ListVector, StrSexpVector, Vector, StrVector
from rpy2.robjects.robject import RObjectMixin, RObject
import numpy as np
import pandas.rpy.common as rcom
import pandas as pd


NA_TYPES = rcom.NA_TYPES
VECTOR_TYPES = rcom.VECTOR_TYPES

baseenv_ri = rinterface.baseenv
globalenv_ri = rinterface.globalenv

# Probably need better logic to detect if xts was imported
robjects.r('require(xts)')

def tz_warning():
    """
        This keeps on catching me
    """
    r_tz = robjects.r('Sys.getenv("TZ")')[0]
    if r_tz == "":
        print "=============WARNING==================="
        print "R Sys TZ is not set. This can get hazardous for your sanity."
        print "Set to your data's TZ or GMT for pandas tz-naive data"
        print "=============WARNING==================="

tz_warning()

def _convert_Matrix(mat):
    columns = mat.colnames
    rows = mat.rownames

    columns = None if rcom._is_null(columns) else list(columns)
    index = None if rcom._is_null(rows) else list(rows)

    # sometimes we don't get shape and data comes in by column
    # and not rows... I have no idea why
    data = np.array(mat)
    if len(data.shape) == 1: 
        data.shape = mat.dim[1],mat.dim[0]
        data = data.T

    return pd.DataFrame(data, index=rcom._check_int(index),
                        columns=columns)

def convert_xts_to_df(o):
    """
        Will convert xts objects to DataFrame
    """
    dates = o.do_slot('index')
    index = convert_posixct_to_index(dates)
    res = robjects.default_ri2py(o)
    df = _convert_Matrix(res)
    df.index = index
    return df<commit_msg>added the actual command to fix the TZ<commit_after>import sys, copy, os, itertools
import time


import rpy2.robjects as robjects
import rpy2.rinterface as rinterface
from rpy2.robjects.vectors import SexpVector, ListVector, StrSexpVector, Vector, StrVector
from rpy2.robjects.robject import RObjectMixin, RObject
import numpy as np
import pandas.rpy.common as rcom
import pandas as pd


NA_TYPES = rcom.NA_TYPES
VECTOR_TYPES = rcom.VECTOR_TYPES

baseenv_ri = rinterface.baseenv
globalenv_ri = rinterface.globalenv

# Probably need better logic to detect if xts was imported
robjects.r('require(xts)')

def tz_warning():
    """
        This keeps on catching me
    """
    r_tz = robjects.r('Sys.getenv("TZ")')[0]
    if r_tz == "":
        print "=============WARNING==================="
        print "R Sys TZ is not set. This can get hazardous for your sanity."
        print "Set to your data's TZ or GMT for pandas tz-naive data"
        print "Sys.setenv(TZ='GMT')"
        print "=============WARNING==================="

tz_warning()

def _convert_Matrix(mat):
    columns = mat.colnames
    rows = mat.rownames

    columns = None if rcom._is_null(columns) else list(columns)
    index = None if rcom._is_null(rows) else list(rows)

    # sometimes we don't get shape and data comes in by column
    # and not rows... I have no idea why
    data = np.array(mat)
    if len(data.shape) == 1: 
        data.shape = mat.dim[1],mat.dim[0]
        data = data.T

    return pd.DataFrame(data, index=rcom._check_int(index),
                        columns=columns)

def convert_xts_to_df(o):
    """
        Will convert xts objects to DataFrame
    """
    dates = o.do_slot('index')
    index = convert_posixct_to_index(dates)
    res = robjects.default_ri2py(o)
    df = _convert_Matrix(res)
    df.index = index
    return df
{'fraction_non_alphanumeric': 0.1257617728531856, 'fraction_numerical': 0.004986149584487534, 'mean_word_length': 3.2135355892648776, 'pattern_counts': {'":': 2, '<': 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': '5869091', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1183, 'n_words': 350}