Skip to content

BUG: TypeError: unsupported operand type(s) for +: 'Timestamp' and 'bytes' #48415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
jeiglsperger opened this issue Sep 6, 2022 · 4 comments
Closed
3 tasks done
Labels
Bug Needs Info Clarification about behavior needed to assess issue

Comments

@jeiglsperger
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
df = pd.DataFrame({'date': ['2018-03-11', '2018-03-18', '2018-03-25', '2018-04-01', '2018-04-08'],
                   'total_turnover': [4789919, 3768344, 3706449, 7335527, 9199346]})
df.set_index("date", drop = True, inplace = True)
df.index = pd.to_datetime(df.index, format='%Y-%m-%d')
df_copy = df.copy()
df_copy = df_copy[0:]

Issue Description

The weirdest part is, that I can not reproduce this error, doesn't matter what I tried. I even exported the .csv of the dataframe I work with but it doesn't reproduce the error. The code above comes the closest that I want to do. I understand, that it's bad to not post a reproducible example, but maybe anyone knows, what changes between the version that causes the error. If not, this bug report can be deleted and I continue working with version 1.0.5.

This line worked perfectly for pandas version 1.0.5. After upgrading it throws this error when doing the slicing df_copy = df_copy[0:]. I also tried to use .iloc which also didn't solve the problem. In my code, instead of the 0, there is this line self.user_input_params["refit_window"], just to clarify for you why I don't just use the complete X_train_val_manip dataframe. The user input self.user_input_params["refit_window"] should allow the user to cut of the first n rows of the dataframe (because they may be outdated).

Expected Behavior

The expected behavior is, that I select the n rows from row n of X_train_val_manip to the end without getting an error.

Installed Versions

INSTALLED VERSIONS

commit : ca60aab
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-46-generic
Version : #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8

pandas : 1.4.4
numpy : 1.23.1
pytz : 2022.1
dateutil : 2.8.2
setuptools : 45.2.0
pip : 20.0.2
Cython : 0.29.17
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2022.5.0
gcsfs : None
markupsafe : 2.1.1
matplotlib : 3.5.2
numba : None
numexpr : 2.8.3
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
snappy : None
sqlalchemy : 1.4.35
tables : 3.7.0
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
zstandard : None

@jeiglsperger jeiglsperger added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 6, 2022
@mroeschke
Copy link
Member

Unfortunately, I cannot reproduce this on 1.4.4 or main

In [1]: import pandas as pd
   ...: df = pd.DataFrame({'date': ['2018-03-11', '2018-03-18', '2018-03-25', '2018-04-01', '2018-04-08'],
   ...:                    'total_turnover': [4789919, 3768344, 3706449, 7335527, 9199346]})
   ...: df.set_index("date", drop = True, inplace = True)
   ...: df.index = pd.to_datetime(df.index, format='%Y-%m-%d')
   ...: df_copy = df.copy()
   ...: df_copy = df_copy[0:]

In [2]: pd.__version__
Out[2]: '1.4.4'

@mroeschke mroeschke added Needs Info Clarification about behavior needed to assess issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 6, 2022
@jeiglsperger
Copy link
Author

That's the weird behavior I described. The error only occurs in my framework, but I can not reproduce what causes this error without posting my whole code...
That's why I wrote that, if nobody else found this behavior and knows a solution, this issue can be deleted due to not reproducible example and I continue with version 1.0.5.

@mroeschke
Copy link
Member

Got it. Yeah unfortunately it would be fairly hard to diagnose for anyone without the full context of the environment.

Some suggestions:

  1. Maybe if your program is modifying important state somewhere.
  2. Reinstall your virtual environment, maybe an errant package is affecting something.
  3. Try upgrading to the 1.5.0rc release to see if something there helps.

Closing otherwise since this isn't fully reproducible.

@jeiglsperger
Copy link
Author

For anyone who's interested, I solved my problem by doing the following:
I changed this function:

def add_valentine_mothersday(df: pd.DataFrame, holiday_public_column: str, special_days: list):
    """
    Function adding valentine's and mother's day to public_holiday column of dataset
    :param df: dataset for adding valentine's and mother's day
    :param holiday_public_column: name of the column containing the public holidays
    :param special_days: special days for the specific data
    """
    if 'Valentine' in special_days:
        # add valentine's day (always 14th of February)
        df.at[[index for index in df.index if (index.day == 14 and index.month == 2)],
                   holiday_public_column] = 'Valentine'
    if 'MothersDay' in special_days:
        # add mother's day (in Germany always second sunday in May)
        df.at[[index for index in df.index
                    if ((index.day-7) > 0 and index.day < 15 and index.weekday() == 6 and index.month == 5)],
                   holiday_public_column] = 'MothersDay'

to

def add_valentine_mothersday(df: pd.DataFrame, holiday_public_column: str, special_days: list):
    """
    Function adding valentine's and mother's day to public_holiday column of dataset
    :param df: dataset for adding valentine's and mother's day
    :param holiday_public_column: name of the column containing the public holidays
    :param special_days: special days for the specific data
    """
    if 'Valentine' in special_days:
        # add valentine's day (always 14th of February)
        for index in df.index:
            if (index.day == 14 and index.month == 2):
                df.at[index, holiday_public_column] = 'Valentine'
    if 'MothersDay' in special_days:
        # add mother's day (in Germany always second sunday in May)
        for index in df.index:
            if ((index.day - 7) > 0 and index.day < 15 and index.weekday() == 6 and index.month == 5):
                df.at[index, holiday_public_column] = 'MothersDay'

This function get's called on the dataset before later on, I tried to do the slicing in some kind of the way I posted above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Info Clarification about behavior needed to assess issue
Projects
None yet
Development

No branches or pull requests

2 participants