We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
import pyarrow as pa import pandas as pd import pytz print("PyArrow:", pa.__version__) print("Pandas:", pd.__version__) table = pa.table([ pa.array([ pd.Timestamp('2014-01-01'), ], type=pa.timestamp("ns")) ], names=["time"]) df = table.to_pandas(self_destruct=True, split_blocks=True) df.set_index("time", inplace=True) df.index = df.index.tz_localize(pytz.utc) # These are OK print(df.index.date) print(df.index.tz_convert("America/New_York")) # But not this print(df.index.tz_convert("America/New_York").date)
The reproduction results in this exception:
Traceback (most recent call last): File "repro.py", line 18, in <module> print(df.index.tz_convert("America/New_York").date) File "/home/lidavidm/Code/twosigma/pandas/temp/venv/lib/python3.8/site-packages/pandas/core/indexes/extension.py", line 54, in fget result = getattr(self._data, name) File "/home/lidavidm/Code/twosigma/pandas/temp/venv/lib/python3.8/site-packages/pandas/core/arrays/datetimes.py", line 1246, in date timestamps = self._local_timestamps() File "/home/lidavidm/Code/twosigma/pandas/temp/venv/lib/python3.8/site-packages/pandas/core/arrays/datetimes.py", line 731, in _local_timestamps return tzconversion.tz_convert_from_utc(self.asi8, self.tz) File "pandas/_libs/tslibs/tzconversion.pyx", line 407, in pandas._libs.tslibs.tzconversion.tz_convert_from_utc File "stringsource", line 658, in View.MemoryView.memoryview_cwrapper File "stringsource", line 349, in View.MemoryView.memoryview.__cinit__ ValueError: buffer source array is read-only
The data is not being modified in place, so it should work with an immutable source array.
This is because tz_convert_from_utc and _tz_convert_from_utc are missing some const specifiers in Cython.
tz_convert_from_utc
_tz_convert_from_utc
const
The .date accessor should work as expected:
.date
[datetime.date(2013, 12, 31)]
pd.show_versions()
commit : d9fff27 python : 3.8.3.final.0 python-bits : 64 OS : Linux OS-release : 5.7.9-arch1-1 Version : #1 SMP PREEMPT Thu, 16 Jul 2020 19:34:49 +0000 machine : x86_64 processor : byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8
pandas : 1.1.0 numpy : 1.19.1 pytz : 2020.1 dateutil : 2.8.1 pip : 20.1.1 setuptools : 47.1.1 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader: None bs4 : None bottleneck : None fsspec : None fastparquet : None gcsfs : None matplotlib : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : 1.0.0 pytables : None pyxlsb : None s3fs : None scipy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None numba : None
The text was updated successfully, but these errors were encountered:
@lidavidm thanks for the report!
A reproducer without pyarrow:
import pandas as pd import pytz arr = pd.array([pd.Timestamp('2014-01-01')]).to_numpy() arr.flags.writeable = False df = pd.DataFrame(index=pd.DatetimeIndex(arr, name="time")) df.index = df.index.tz_localize(pytz.utc) df.index.tz_convert("America/New_York").date
Sorry, something went wrong.
BUG: handle immutable arrays in tz_convert_from_utc (pandas-dev#35530)
6c98bdb
b4a1de2
4b09568
f60c88f
bbe89f0
BUG: handle immutable arrays in tz_convert_from_utc (#35530) (#35532)
69cd744
Successfully merging a pull request may close this issue.
There are similar issues with the same symptom
Tested with Pandas 1.1.0
Tested with bdcc5bf
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
The reproduction results in this exception:
The data is not being modified in place, so it should work with an immutable source array.
This is because
tz_convert_from_utc
and_tz_convert_from_utc
are missing someconst
specifiers in Cython.Expected Output
The
.date
accessor should work as expected:Output of
pd.show_versions()
INSTALLED VERSIONS
commit : d9fff27
python : 3.8.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.7.9-arch1-1
Version : #1 SMP PREEMPT Thu, 16 Jul 2020 19:34:49 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.0
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 47.1.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.0
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: