Skip to content
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

BUG: Timestamp.to_julian_date() does not take into account timezone #54763

Open
2 of 3 tasks
danmoser opened this issue Aug 25, 2023 · 4 comments · May be fixed by #60280
Open
2 of 3 tasks

BUG: Timestamp.to_julian_date() does not take into account timezone #54763

danmoser opened this issue Aug 25, 2023 · 4 comments · May be fixed by #60280
Assignees
Labels
Bug Timestamp pd.Timestamp and associated methods Timezones Timezone data dtype

Comments

@danmoser
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
import pytz

ts = pd.Timestamp('1858-11-17T00:00:00.0', tzinfo=pytz.utc)
ts
# Timestamp('1858-11-17 00:00:00+0000', tz='UTC')
ts.to_julian_date()
# 2400000.5

ts = pd.Timestamp('1858-11-17T00:00:00.0', tzinfo=pytz.timezone('US/Mountain'))
ts
# Timestamp('1858-11-17 00:00:00-0700', tz='US/Mountain')
ts.to_julian_date()
# 2400000.5
# it should be 2400000.7916666665

pd.__version__
# '2.0.3'

pytz.__version__
# '2022.1'

Issue Description

Timestamp.to_julian_date() does not take into account the timezone information.

Expected Behavior

ts
# Timestamp('1858-11-17 00:00:00-0700', tz='US/Mountain')
ts.to_julian_date()
# 2400000.5
# it should be 2400000.7916666665

Installed Versions

INSTALLED VERSIONS
------------------
commit           : 0f437949513225922d851e9581723d82120684a6
python           : 3.8.13.final.0
python-bits      : 64
OS               : Linux
OS-release       : 4.18.0-372.32.1.el8_6.x86_64
Version          : #1 SMP Fri Oct 7 12:35:10 EDT 2022
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 2.0.3
numpy            : 1.23.1
pytz             : 2022.1
dateutil         : 2.8.2
setuptools       : 68.0.0
pip              : 23.2
Cython           : 0.29.15
pytest           : 7.3.1
hypothesis       : None
sphinx           : 4.3.0
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : 4.9.1
html5lib         : 1.1
pymysql          : None
psycopg2         : 2.9.6
jinja2           : 3.1.2
IPython          : 7.29.0
pandas_datareader: None
bs4              : 4.12.0
bottleneck       : None
brotli           : None
fastparquet      : None
fsspec           : 2023.3.0
gcsfs            : None
matplotlib       : 3.5.1
numba            : None
numexpr          : None
odfpy            : None
openpyxl         : 3.1.2
pandas_gbq       : None
pyarrow          : None
pyreadstat       : None
pyxlsb           : None
s3fs             : None
scipy            : 1.9.0
snappy           : None
sqlalchemy       : 2.0.19
tables           : None
tabulate         : 0.8.9
xarray           : None
xlrd             : None
zstandard        : None
tzdata           : 2023.3
qtpy             : None
pyqt5            : None
@danmoser danmoser added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 25, 2023
@rsm-23
Copy link
Contributor

rsm-23 commented Aug 30, 2023

@danmoser can you please update the title with a meaningful description?

@danmoser danmoser changed the title BUG: BUG: Timestamp.to_julian_date() does not take into account timezone Aug 30, 2023
@danmoser
Copy link
Author

@danmoser can you please update the title with a meaningful description?

Done!

@jbrockmendel jbrockmendel added the Timestamp pd.Timestamp and associated methods label Nov 1, 2023
@mroeschke mroeschke added Timezones Timezone data dtype and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 17, 2024
@AdamRJensen
Copy link

AdamRJensen commented Oct 2, 2024

This is indeed an issue! Julian Dates shouldn't be timezone dependent.

def to_julian_date(self) -> npt.NDArray[np.float64]:
"""
Convert Datetime Array to float64 ndarray of Julian Dates.
0 Julian date is noon January 1, 4713 BC.
https://en.wikipedia.org/wiki/Julian_day
"""
# http://mysite.verizon.net/aesir_research/date/jdalg2.htm
year = np.asarray(self.year)
month = np.asarray(self.month)
day = np.asarray(self.day)
testarr = month < 3
year[testarr] -= 1
month[testarr] += 12
return (
day
+ np.fix((153 * month - 457) / 5)
+ 365 * year
+ np.floor(year / 4)
- np.floor(year / 100)
+ np.floor(year / 400)
+ 1_721_118.5
+ (
self.hour
+ self.minute / 60
+ self.second / 3600
+ self.microsecond / 3600 / 10**6
+ self.nanosecond / 3600 / 10**9
)
/ 24
)

@tev-dixon
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timestamp pd.Timestamp and associated methods Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants