Skip to content

Commit 0393592

Browse files
committed
Silence warnings about writing NPZ files with StringDType
1 parent 3502695 commit 0393592

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

NEWS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
PENDING: Dataiter 1.0
2+
=====================
3+
4+
* Silence warnings about writing NPZ files with StringDType:
5+
"UserWarning: Custom dtypes are saved as python objects using the
6+
pickle protocol. Loading this file requires allow_pickle=True to be
7+
set."
8+
19
2025-01-12: Dataiter 0.9999
210
===========================
311

dataiter/dtypes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222

23+
import warnings
24+
2325
from numpy.dtypes import StringDType
2426

2527
#: Instance of NumPy variable-width StringDType used
@@ -30,3 +32,7 @@
3032
# input, a distinction between NA and blank cannot usually be made.
3133
# TODO: Consider changing this to something like ':NA:'.
3234
# https://numpy.org/doc/stable/user/basics.strings.html#missing-data-support
35+
36+
# Ignore pointless warnings about using StringDType in numpy.savez.
37+
_pattern = "Custom dtypes are saved as python objects using the pickle protocol"
38+
warnings.filterwarnings("ignore", message=_pattern, category=UserWarning)

dataiter/test/test_data_frame.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
from pathlib import Path
3232
from unittest.mock import patch
3333

34-
# This UserWarning seems unavoidable when using StringDtype, which unlike
35-
# other dtypes must be instantiated and that custom instance used.
36-
IGNORE_NPZ_PICKLE_WARNING = "ignore:Custom dtypes are saved as python objects using the pickle protocol."
34+
# See dataiter/dtypes.py for the equivalent non-test ignore.
35+
IGNORE_NPZ_PICKLE_WARNING = "ignore:Custom dtypes are saved as python objects using the pickle protocol"
3736

3837
class TestDataFrameColumn:
3938

0 commit comments

Comments
 (0)